The simplest method to vertically center your elements while using XHTML is to use the table property of the div tag. With this method you can style your div to act like a table with a cell under it.
|
1 2 3 4 5 |
<div style="border:1px solid #000;display:table;height:150px;width:200px;">
<div style="display:table-cell;vertical-align:middle;">
Vertically centered text
</div>
</div> |
Vertically centered text
As you can see above, the code has made the text become vertically centered. The text is not horizontally centered but that’s just as easy with the well known margin:0 auto; horizontal center method, or even text-align:center;.
Related posts:
- Embedding Flash Files With Valid XHTML (Strict) I’m sure a lot of people want to know the...
- XHTML Strict & target=”_blank” (and _top) I had made a post a few days ago regarding...
- Rotating Script for Text Ads, Banner Ads or Interstitials (or Anything Else!) The following are simple instructions to create a script to...

0 Comments.