Html 位置固定和 Internet Explorer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1193255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Position fixed and Internet Explorer
提问by Riga
this is my css. It is working fine in firefox but not working in IE.
这是我的 css。它在 Firefox 中运行良好,但在 IE 中不起作用。
#Createinner {
position: fixed;
width: 400px;
height: 280px;
margin-left: -200px;
margin-top: -140px;
top: 50%;
left: 50%;
background-color: #ccc;
}
How to solve this.
如何解决这个问题。
Thanks in advance
提前致谢
回答by Niraj
Simply add DocType Tag on top of the page
只需在页面顶部添加 DocType 标签
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
回答by Riga
What sorted my problem with IE was the code in:
对我的 IE 问题进行排序的是以下代码:
http://annevankesteren.nl/test/examples/ie/position-fixed.html
http://annevankesteren.nl/test/examples/ie/position-fixed.html
basically added:
基本补充:
h1{
position:fixed;
_position:absolute;
top:0;
_top:expression(eval(document.body.scrollTop));
}
回答by ali.b.y
for fixed position in IE 8 DOCTYPEis very very important.
对于固定位置在 IE 8 DOCTYPE 中是非常非常重要的。
one of:
之一:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
or
或者
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
or
或者
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
or
或者
<!DOCTYPE HTML>
And its very very important that
非常非常重要的是
those be in first line.
那些在第一线。
css:
css:
#footer
{position: fixed; right: 0px; bottom: 0px; }
html:
html:
<div id="footer" >
Fixed Div
</div>
回答by Chris Iona
I recently wrote a jQuery plugin to get position:fixed working in IE 6+. It doesn'tjitter on scroll, it looks at capability (not user-agent), works in Internet Explorer 6, 7, 8.
我最近写了一个 jQuery 插件来获取 position:fixed 在 IE 6+ 中的工作。它在滚动时不会抖动,它查看功能(而不是用户代理),适用于 Internet Explorer 6、7、8。
If you use strict mode in IE7+ position:fixed will be honoured, but by default IE7+ operates in Quirks Mode. This plugin checks for browser capability, and if it doesn't honour position:fixed, then it implements the jQuery fix.
如果您在 IE7+ 中使用严格模式 position:fixed 将受到尊重,但默认情况下 IE7+ 在 Quirks 模式下运行。该插件检查浏览器功能,如果它不支持 position:fixed,则它实现 jQuery 修复。
http://code.google.com/p/fixedposition/
http://code.google.com/p/fixedposition/
Something like this may work for you:
像这样的事情可能对你有用:
$(document).ready(function(){
$("#Createinner").fixedPosition({
debug: true,
fixedTo: "bottom"
});
});
You may need to make some minor CSS adjustments to get it working for your code. I'm working on "offset" values as options as we speak.
您可能需要进行一些小的 CSS 调整才能使其适用于您的代码。正如我们所说,我正在研究“偏移”值作为选项。
回答by edeverett
IE6 doesn't support position fixed.
IE6 不支持位置固定。
If you really need this to work in IE6, use conditional comments to serve an IE only CSS file and fake position:fixed
with CSS expressions.
如果您真的需要在 IE6 中使用它,请使用条件注释来提供 IE 唯一的 CSS 文件并position:fixed
使用 CSS 表达式伪造。
(edited to correct IE version info.)
(编辑以更正 IE 版本信息。)
回答by Frozenskys
- Versions of IE pre 8 do not support position fixed properly.
- What is the problem with the CSS e.g. why is it not working, what do you see on the screen?
- IE pre 8 的版本不支持正确定位。
- CSS 有什么问题,例如为什么它不起作用,您在屏幕上看到了什么?
回答by user1241761
http://ieproblems.blogspot.com/use this one it will solve your problem
http://ieproblems.blogspot.com/使用这个它会解决你的问题
#mainDiv{
overflow:auto;
}
#subDiv{
position:relative;
top:expression(this.offsetParent.scrollTop+'px');
left:expression(this.offsetParent.scrollTop+'px');
}
<html>
<head>
</head>
<body>
<div id="mainDiv">
<div id="subDiv">
This Text is Fixed
</div>
</div>
</body>
</html>
回答by Quentin
IE 6 does not support position: fixed
IE 6 不支持 position: fixed
- Use workaroundsif you need to support IE6
- 如果您需要支持 IE6,请使用变通方法
Other versions of IE don't support position: fixed
in quirks mode
其他版本的 IE 不支持position: fixed
quirks 模式
- Use a standards mode triggering Doctype(generally HTML 4.01 Strict is the right choice)
- 使用触发 Doctype的标准模式(通常 HTML 4.01 Strict 是正确的选择)