css: center content
dilluns, març 30th, 2009When I began playing with CSS, centering a page was rather difficult. CSS allowed it, but try a search «center content» or «center css». It throws lots of results, and most of them, when I needed it, were not relevant. The trick is margin: 0 auto;
Create a <div> where you’ll put all contents, with id=”content”, for example.
<html> <body> <div id="content"> <p>Today's a good day to code.</p> </div> </body> </html>
Now, in a style sheet create a rule:
#content { width: 1024px; margin: 0 auto 0 auto; }
And enjoy your centered content