Question:
As the HTML <center> tag has been deprecated, how does one center a page using CSS
- like the Pierce College page, for example?
Answer:
body {
text-align: center;
}
#pageDiv {
width: 58em;
margin-left: auto;
margin-right: auto;
text-align: left;
}
Note:
"text-align: center;" was needed for older versions of IE.
Example:
View the source code of:
my Pierce College page
Comment:
Notice that IE always has scroll bars on the right (disabled if not needed),
while other browsers have scroll bars that come-and-go as needed.
That means: shorter pages shift right, and longer pages shift left.
However, that is not an issue centering content inside a div tag that does not move.
For example, the Student Scores signon form on this website is centered within its container. e.g.
body {
text-align: left;
}
...
#containerDiv {
text-align: center;
}
#centerTable {
margin-left: auto;
margin-right: auto;
text-align: left;
}