开发者

Centring fixed width DIV inside 100% width parent DIV

开发者 https://www.devze.com 2022-12-21 06:08 出处:网络
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\">

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消