将固定宽度DIV居中放在100%宽度的父DIV中

时间:2022-07-10 20:22:06

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 :-)

任何人都知道发生了什么以及如何解决它。我知道文本对齐技巧,但必须有一个更好的方法。我讨厌邋code的代码:-)

Cheers

干杯

1 个解决方案

#1


0  

Text-align trick is something I've used. I hate sloppy code too, but hey, it's IE.

文字对齐技巧是我用过的东西。我也讨厌邋code的代码,但是嘿,这是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.

我想到的一点是,您可能需要将宽度设置为其外的所有元素。尝试将宽度设置为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?

你错过了自己的身体标签,你注意到,因为你的代码距离有效,所以这只是一个例子吗?

#1


0  

Text-align trick is something I've used. I hate sloppy code too, but hey, it's IE.

文字对齐技巧是我用过的东西。我也讨厌邋code的代码,但是嘿,这是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.

我想到的一点是,您可能需要将宽度设置为其外的所有元素。尝试将宽度设置为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?

你错过了自己的身体标签,你注意到,因为你的代码距离有效,所以这只是一个例子吗?