如何让 DIV 在 IE8 中具有正确的宽度?
这听起来很简单,但我被困住了。我需要在 IE8 中将 DIV 设置为 434 像素宽。以下是我的代码。这在 FF 中有效,但 IE8 始终以 414 像素的宽度呈现 DIV。为什么要砍掉20个像素?
<html>
<head>
<style type="text/css">
#box
{
width:434px;
background-color:red;
margin:0;
padding:0;
}
</style>
</head>
<body>
<div id="box"> </div>
</body>
</html>
我也在严格模式下尝试过,结果相同。
This sounds pretty simple, but I am stuck. I need to set a DIV to be 434 pixels wide in IE8. The following is my code. This works in FF, but IE8 always renders the DIV with a width of 414 pixels. Why does it chop off 20 pixels?
<html>
<head>
<style type="text/css">
#box
{
width:434px;
background-color:red;
margin:0;
padding:0;
}
</style>
</head>
<body>
<div id="box"> </div>
</body>
</html>
I've also tried it in strict mode, with the same result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IE 使用滚动条做了一些奇怪的事情,并在宽度中考虑了这些。当您采取 时会发生什么?出去?
IE does weird things with scroll bars, and accounts those in the width. What happens when you take the out?
Elmonty,请看看 IE8 中宽度和高度是如何变短的。我认为这是一个常见的渲染问题。 IE8 中的画布将显示比其他浏览器更短的对象。例如,加载 此页面在两个浏览器中以及两者之间的Alt+Tab,您将看到发生了什么...
希望有帮助,
Elmonty, please look how not only width but height is shorter in IE8. I think this is a common rendering issue. The canvas in IE8 will show you the objects shorter than the other browsers do. As an example, load this page in both browsers and Alt+Tab between both and you will see what is going on...
Hope that helps,
之前我曾遇到过利润问题。我不太记得了,但我更改了边距和边距的设置值。填充如下:
而不是:
请尝试这个小改变&如果这就是你的 20px 的原因,请告诉我。
EDIT : Please ignore this answer as it is inappropriate.
正如 raymon 所指出的,浏览器将呈现您给出的完全相同的代码片段。您的问题可能是由于其他一些因素造成的......
Somewhere before I faced a problem of margins. I don't remember for sure, but I changed the set the values for margin & padding as this :
rather than :
Please try this little change & let me know if this was what was chopping your 20px.
EDIT : Please ignore this answer as it is inappropriate.
As pointed out by raymon, the browsers would render the piece of code you gave exactly the same. Your problem is probably due to some other factors....