Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 位置:在IE中不使用doctype的情况下修复_Html_Css_Internet Explorer - Fatal编程技术网

Html 位置:在IE中不使用doctype的情况下修复

Html 位置:在IE中不使用doctype的情况下修复,html,css,internet-explorer,Html,Css,Internet Explorer,如何在不使用的情况下修复HTML页面中的元素 在样式()中使用(例如,位置:绝对或位置:固定): 绝对值(与页面一起滚动): 主题外,但我总是建议使用DOCTYPE。如果没有它,几乎每个浏览器都会遇到不同的怪癖。虽然DOCTYPE与浏览器之间仍然存在差异,但它们的差异更小,也不那么疯狂……绝对或固定位置元素的关键在于它的父元素(比如容器div)必须具有位置:相对 例如,如果您有一个960px宽且位于页面中心的容器div(如下所示): 就像上面提到的TJ一样,固定位置保持不变,即使用户滚动时也是

如何在不使用
的情况下修复HTML页面中的元素

在样式()中使用(例如,
位置:绝对
位置:固定
):

绝对值(与页面一起滚动):



主题外,但我总是建议使用DOCTYPE。如果没有它,几乎每个浏览器都会遇到不同的怪癖。虽然DOCTYPE与浏览器之间仍然存在差异,但它们的差异更小,也不那么疯狂……

绝对或固定位置元素的关键在于它的父元素(比如容器div)必须具有
位置:相对

例如,如果您有一个960px宽且位于页面中心的容器div(如下所示):

就像上面提到的TJ一样,固定位置保持不变,即使用户滚动时也是如此,其中绝对位置只是相对于元素定位,并将与其余内容一起滚动


同样,我也会始终推荐使用doctype。

javascript
似乎与此无关?您应该始终使用doctype。我想不出一个不使用doctype的理由。我也看不出doctype有什么关系,除非它是关于在怪癖模式下固定位置的东西。@Felix:除非问题是如何使用JavaScript。事实上,我们只是在猜测……这是绝对定位——div仍然会随着页面滚动。@BoltClock的独角兽:这可能是他/她想要的,也可能不是(或者你认为提问者对此非常清楚,以至于他知道“固定”是一个CSS术语?)。正如你所评论的,我添加了CSS2.1的链接,并提到了固定定位。好的,公平点。但是,否决票不是我的,我将+1进行编辑。
<style type='text/css'>
#foo {
    position: absolute;
    left: 10px;
    top: 10px;
}
</style>
<div id='foo'>This is foo at 10x10</div>
<div style='position: absolute; left: 10px; top: 10px;'>This is foo at 10x10</div>
<style type='text/css'>
#foo {
    position: fixed;
    right: 10em;
    top: 2em;
}
</style>
<div id='foo'>This is foo at 10x10</div>
<div style='position: fixed; right: 10em; top: 2em;'>This is foo in the upper right</div>
var div = document.getElementById('foo');
div.style.position = "absolute"; // or "fixed" or whatever
div.style.left = "10px";
div.style.top = "10px";
<div class="container">
   <div id="AbsolutePositionedBox">
        // Box Content Goes Here
   </div>
</div>
.container{
    width:960px; 
    position: relative;
    margin: 0 auto;
}
    #AbsolutePositionedBox{
        position: // absolute or fixed;
        top: // pixels from the RELATIVE parent (makes it easier to manage);
        LEFT OR RIGHT: // pixels from the RELATIVE parent;
    }