html - 在 IE8 模式下单击相邻文本时文本移动

标签 html css

我被难住了。我的页面上有一个段落,当我使用 IE8 浏览该页面时,单击该段落会导致附近的一些文本向上移动。我已经剥离了所有内容以获得良好的复制。在我的复制案例中,它实际上更糟。如果我单击其他一些文本,它会导致文本向下移动。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>IE8 text shift</title>
</head>
<body>
    <div style="margin: 100px 0;">margin</div>
    <div style="width:32px; height:32px; float:left; background: Yellow;">float</div>
    <div>
        <!-- This HTML comes from an external system.  I cannot remove      -->
        <!-- the <div style="clear:both;"></div>, which is always included. -->
        <p>Click on this first paragraph and the "abc" text jumps up.</p>
        <p>Click on this second paragraph and the "abc" text jumps down.</p>
        <div style="clear:both;"></div>
        <!-- End External HTML -->
    </div>
    <div>abc</div>
</body>
</html>

我很乐意删除 <div style="clear:both;"></div>除了这是我无法控制的。评论指出的区域之外的一切都在我的控制之中。

在 chrome 和 firefox 中运行良好。

编辑: 看来我对第一段需要很长的看法是错误的。事实上,如果它太长,我会失去我的复制品。我已经更新了我的复制品以使用较短的第一段。

编辑: 它与顶部 div 的边距有关。如果我添加更多段落,这种转变就会消失。但是,如果我随后增加该 div 的边距,就会返回。

更新:我确认这不会在实际的 ie 8 中重现(必须使用我的旧 XP 计算机)。这只是 IE8 模式下的 IE9 问题。 此外,我发现我可以通过添加 style="overflow: hidden; 来修复它到段落的父 div。

最佳答案

此问题特定于 IE9-in-IE8-模式。解决办法是隐藏父div的溢出。

<body>
    <div style="margin: 100px 0;">margin</div>
    <div style="width:32px; height:32px; float:left; background: Yellow;">float</div>
    <div style="overflow: hidden">
        <p>Click on this first paragraph and the "abc" text no longer jumps up.</p>
        <p>Click on this second paragraph and the "abc" text no longer jumps down.</p>
        <div style="clear:both;"></div>
    </div>
    <div>abc</div>
</body>

关于html - 在 IE8 模式下单击相邻文本时文本移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5902672/

相关文章:

javascript - 使用 OpenCPU 显示 R 函数的 html 返回

javascript - 我的网站在启动时加载在底部

html - Flex Layout、纵横比、固定宽度和动态宽度列

javascript - 使用菜单移动内容

html - Bootstrap,如何以正确的方式将标题对齐到缩略图中图像的右侧,并将按钮对齐到标题的底部?

html - 为什么下拉列表在 DIV 下方而不是上方

html - 边距忽略顶部、右侧和底部 CSS、HTML

javascript - 使动态创建的下拉菜单与初始下拉菜单中的 Vue 模型中的值匹配

javascript - 单击元素时更改背景颜色 - CSS(无 jQuery)

javascript - 我怎样才能强制溢出:scroll when using plugin for responsive-tables?