Centring fixed width DIV inside 100% width parent DIV
I have a setup similar 开发者_StackOverflow社区to below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml”>
<div id=“a” style=“width: 100%”>
<div id=“b” style=“width: 200px; margin: 0 auto”>
</div>
</div>
And this centres fine in everything except IE.
Anyone have any idea what is going on and how to fix it. I know of the text-align trick, but there must be a better method. I hate sloppy code :-)
Cheers
Text-align trick is something I've used. I hate sloppy code too, but hey, it's IE.
Something that comes to my mind is that maybe you need to set the width to all elements outside it. Try setting width to html and body too.
You're missing your body tag, you noticed that, as your code is so far away from valid, this must be just an example right?
精彩评论