html - float div 在 IE7 中扩展到 100%

标签 html css internet-explorer

我有以下简单布局:

div.main
{
    width: 300px;
    border: 2px solid #98999E;
    overflow: auto;
}
div.main > div
{
    float: right;
    border: 2px solid #FF3700; 
    margin: 2px;
}
div.inner > div
{
     float: right;
}

<div class="main">
    <div class="inner">
        <div>123</div>
        <div>456</div>
    </div>
    <div>999</div>
</div>

在 Chrome 和 Firefox 中,这是按预期呈现的 - 所有内容都在同一行中: enter image description here

但是,当在 IE7 中测试时(准确地说,实际上是在兼容模式下的 IE8),主要部分下面的第一个 div 的宽度为 100%,因此第二个 div 被推到它下面: enter image description here

可以在 here 中找到示例。

如何解决?

(编辑: 事实证明,这在兼容模式下的 IE9 中也发生了)

(编辑 2: 这似乎只发生在 float:right 上,而不发生在 float:left 上)

最佳答案

display: inline;display: inline-block; 应用于内部 div。

w3.org - 9.2.2 Inline-level elements and inline boxes

关于html - float div 在 IE7 中扩展到 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7262279/

相关文章:

html - 仅删除 1 项的填充

css - Flexbox:反转顺序并将第一个 block 放在新行中

css - moz-transform scale decrease div size问题

javascript - 如何在 IE 中自动允许被阻止的内容?

html - 布局在 Bootstrap 中搞砸了

html - 响应式网页设计 - 消失的风格?

css - 样式属性文本阴影给出错误无效参数

css - IE 8 在打印时复制第一个元素

jquery - Internet Explorer 8 和 jQuery : click() for element with transparent background

javascript - 仅在必要时水平滚动