html - margin: 0px auto VS margin: -50% -
i'm write templates new little project - , wondered 1 thing:
if want whole page content inside centered column, - lets - 800px width, usual way of doing (at least, way did it):
<html> <head> <style> body { text-align: center; /* ie6 */ } #wrapper { margin: 0px auto; width: 800px; background-color: #eee; /* see better */ text-align: left; /* ie6 */ } </style> </head> <body> <div id="wrapper"> ... content ... </div> </body> </html> now, there method same thing, margin: -50%; (or fixed value, in case margin: 400px;), this:
<html> <head> <style> body { margin-left: 50%; } #wrapper { margin-left: -400px; width: 800px; background-color: #eee; /* see better */ } </style> </head> <body> <div id="wrapper"> ... content ... </div> </body> </html> my question - 1 of 2 methods have advantages on other? or disadvantages? there common 'best solution' centering main column?
margin:0 auto; make sure there equal amounts of space on either side of element.
margin-left:50%; relative parent. example, if container 1000px wide, have left margin of 500px on child element. however, not center element, place it's left side in middle — unless hack fixed value on child element in example.
usually, when dealing wrapper in case, margin:0 auto; simplest , flexible solution. in other cases, might find better use percentage or fixed value (for example, when floating stuff).
Comments
Post a Comment