如何让 DIV 在 IE8 中具有正确的宽度?

发布于 2024-09-24 05:08:53 字数 449 浏览 1 评论 0原文

这听起来很简单,但我被困住了。我需要在 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">&nbsp;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三五鸿雁 2024-10-01 05:08:53

IE 使用滚动条做了一些奇怪的事情,并在宽度中考虑了这些。当您采取   时会发生什么?出去?

IE does weird things with scroll bars, and accounts those in the width. What happens when you take the   out?

丘比特射中我 2024-10-01 05:08:53

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,

森罗 2024-10-01 05:08:53


之前我曾遇到过利润问题。我不太记得了,但我更改了边距和边距的设置值。填充如下:

margin :0px 0px 0px 0px;
padding :0px 0px 0px 0px;

而不是:

margin :0;
padding :0;

请尝试这个小改变&如果这就是你的 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 :

margin :0px 0px 0px 0px;
padding :0px 0px 0px 0px;

rather than :

margin :0;
padding :0;

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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文