如何使用 TRANSITIONAL doctype 使“位置:固定”css 在 IE 7+ 中工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1628265/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:12:05  来源:igfitidea点击:

How to get "position:fixed" css to work in IE 7+ with TRANSITIONAL doctype?

cssinternet-explorer-7doctype

提问by roman m

I know that position:fixed;was not supported by IE until IE 7, and it only works in IE 7 if you have a STRICT DOCTYPE.

我知道position:fixed;直到 IE 7 才被 IE 支持,如果你有一个STRICT DOCTYPE.

My question is: "How do I get it work with IE 7 with TRANSITIONAL DOCTYPE?"

我的问题是:“我如何让它与 IE 7 一起工作TRANSITIONAL DOCTYPE?”

Please don't suggest changing a DOCTYPE, as this does not answer my question, thank you.

请不要建议更改 a DOCTYPE,因为这不能回答我的问题,谢谢。

回答by bobince

You don't need a Strict DOCTYPE for fixedsupport. You only need a DOCTYPE that triggers Standards Mode(or ‘almost standards'). That can be a transitional doctype such as:

您不需要 Strict DOCTYPE 来fixed提供支持。您只需要一个触发标准模式(或“几乎标准”)的 DOCTYPE 。这可以是一个过渡文档类型,例如:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

or XHTML:

或 XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

as long as the system ID (the URI at the end) is included.

只要包含系统 ID(末尾的 URI)。

If your pages really arerelying on Quirks Mode (ugh!), I'm sorry but you cannot use fixedand will have to resort to JavaScript hacks (but then you might need those for IE6 anyway).

如果您的网页确实依靠Quirks模式(啊!),我很抱歉,但你不能使用fixed,将不得不诉诸JavaScript的黑客(但你可能需要那些IE6无论如何)。

回答by Asad Hasan

Fixed position does not work for me even with the Transitional/Strict Doc types. However I am using IE9 in compatibility mode and that is suppose to render using the IE8 runtime libraries. To fix this issue I had to add the following CSS to element.

即使使用 Transitional/Strict Doc 类型,固定位置对我也不起作用。但是,我在兼容模式下使用 IE9,并且假设使用 IE8 运行时库进行渲染。为了解决这个问题,我必须将以下 CSS 添加到元素中。

.elementToBeFixed {
    position: fixed;
    top: 0;
    left: 0;
}

It does not work with Top or Left being missing you have to explicitly set them to zero (or your desired value) for it to work in all versions of IE....Needless to say IE sucks.

它不适用于缺少 Top 或 Left 您必须明确将它们设置为零(或您想要的值)才能在所有版本的 IE 中工作....不用说 IE 很烂。