简体   繁体   English

在100%宽度的父DIV内部居中固定宽度DIV

[英]Centring fixed width DIV inside 100% width parent DIV

I have a setup similar 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. 除了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. 我也讨厌草率的代码,但是,嘿,它是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. 尝试将width设置为html和body。

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? 您缺少身体标签,您注意到,由于您的代码与有效代码相距甚远,因此这仅是示例吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM