我在 IE7 中遇到了一些非常奇怪的行为。我想定位我的 <body>
-标记亲属。
如果我输入
body { position: relative; }
在我的 css 文件中,我的菜单(position:absolute)不起作用。但是如果我使用
<body style="position: relative;">
它有效。这怎么可能有所作为?没有删除 css 属性或类似属性的 javascript。
最佳答案
对此感到好奇,但就问题而言,@thirtydot 的评论似乎是正确的:答案是没有区别。我创建了 this jsfiddle它在 IE7 中按预期呈现(老实说:我在 IE9 中使用 IE7 模式对其进行了测试)。
代码如下:
<html><head></head>
<body>
<div class="menu">HOME | PRODUCTS | ABOUT</div>
<p>Testing!</p><p>Testing!</p><p>Testing!</p><p>Testing!</p>
</body>
</html>
相关的 CSS,用一些颜色来可视化事物:
html {
background-color: green;
}
div.menu {
border: 1px solid blue;
background-color: silver;
position: absolute;
right: 10px;
top: 10px;
}
body {
background-color: pink;
width: 90%;
position: relative;
left: 10px;
top: 10px;
}
如预期的那样给我:
它在 IE9 和 FF 中对我来说呈现相似。
关于html - <body> 位置 : relative, 内联 VS .css 文件 (IE7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10564903/