CHAPTER#5: CENTERING A CONTENT
Mademoiselle; a layout tutorial threadCHAPTER 5: CENTERING A CONTENT
Hi everyone! I haven't updated for a while so here's a simple tutorial. (In case you have no idea how to do this).
Centering a content is very important. We have no ruler in the eye so we can't measure exactly right?
So here's the magic trick
< div style="margin: 0px auto " >
This simply sets the left and right margins to automatic, while leaving the top and bottom margins 0. Simple huh? HOWEVER, this could be a little more tricky.
One problem is that:
It does not center!
Well, if you have a div which holds all the other divs, make sure you specify the "centering div's" width with a width exactly suitable for it's contents (if you have a 200px image and 200px another div for text, make it's width 400, given no margin in between the contents). Like this:
< div style="margin: 0px auto;width:400px" >
Another problem is that:
The contents are behind another content!
That is why you have to put a < div style="float:left " > inside our centering div! And this is where you will adjust all your margins, background-color and such.
So here's a demonstartion:
IMAGE
TEXTS
Centering a content is very important. We have no ruler in the eye so we can't measure exactly right?
So here's the magic trick
< div style="margin: 0px auto " >
This simply sets the left and right margins to automatic, while leaving the top and bottom margins 0. Simple huh? HOWEVER, this could be a little more tricky.
One problem is that:
It does not center!
Well, if you have a div which holds all the other divs, make sure you specify the "centering div's" width with a width exactly suitable for it's contents (if you have a 200px image and 200px another div for text, make it's width 400, given no margin in between the contents). Like this:
< div style="margin: 0px auto;width:400px" >
Another problem is that:
The contents are behind another content!
That is why you have to put a < div style="float:left " > inside our centering div! And this is where you will adjust all your margins, background-color and such.
So here's a demonstartion:
IMAGE
TEXTS
Here's the codes used
< div style="margin: 0px auto;width:400px;" >
< div style="float:left;width:400px;" >
< div style="float: left; width: 200px; height: 200px; text-align: center; background-color: rgb(204, 204, 204);" >< br / >
< br / >
< br / >
< br / >
< br / >
< br / >
< span style="color:#696969;" >IMAGE< /span >< /div >
< div style="float: left; width: 200px; height: 200px; text-align: center; background-color: rgb(211, 211, 211);" >< br / >
< br / >
< br / >
< br / >
< br / >
< br / >
< span style="color:#696969;" >TEXTS< /span >< /div >
< /div >
< /div >
The text in bold does the centering while the italicized one just hold the contents to prevent them from being overlapped by other contents.
Comments