# [web] Aligning text within a div.

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I tried using text-align: center; like you would in a table but it doesn't work. Is there a way to do this? Here's my source.
#menu{
margin-left: 0px;
width: 150px;
height: 100%;
text-align: center;
}


EDIT: Should i just use the < center > tags I thought they were depricated tho. EDIT2: Nope center tags don't work they center in the whole screen. Thanks in advance,

##### Share on other sites
SOLUTION:
Figured it out. I just make a table within my div with the same width as the div. And it is defaulted to centered text [smile]

##### Share on other sites
text-align: center; should work. I think that one of the tags after that is overwriting the text-align attribute again. Check for that. Tables should be used for tabular data only, not for layout.

##### Share on other sites
<Div Align="center"> should work just fine as well.. But I hate DIV tags.

##### Share on other sites
the align HTML attribute is depreciated in favour of CSS. I'd recommend figuring out the error in your CSS code. Got a link to the page in question?

##### Share on other sites
Probably your div element is not set with 100% of the width of the parent.

Text-align:center only centres the text in the element that it's in. If that element itself is not the full width, the text will still appear left aligned (if that is the rule which applies to the parent).

Internet explorer has a bug which in some circumstances makes text-align:center centre elements which it shouldn't. Beware of this.

Internet explorer has another bug which causes it to incorrectly interpret margin-left:auto;margin-right:auto

The latter is what should really be used to centre a block-level element within another. But in IE it doesn't work, so you have to use the incorrect text-align:center

Mark

• 23
• 10
• 19
• 15
• 14