• Advertisement
Sign in to follow this  

[web] Aligning text within a div.

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement