CSS 是什么让 Internet Explorer 进入怪癖模式?

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

What throws Internet Explorer into quirks mode?

cssinternet-explorerxhtmlw3c-validationquirks-mode

提问by mat_o

I have created a webpage (http://www.snow4life.yum.pl) that was rendered properly in firefox, chrome etc. Of course dumb IE complicated things, because it enters quirk mode automatically, even though doctype is properly set and site goes through w3 validation(there is one error of missing some char, but file was cleared in hex editor). How can I stop ie from entering quirks mode ? Is there any way ?

我创建了一个网页(http://www.snow4life.yum.pl),它在 firefox、chrome 等中正确呈现。当然愚蠢的 IE 复杂的东西,因为它自动进入怪癖模式,即使正确设置了 doctype 和站点通过w3 验证(有一个错误是缺少某些字符,但文件已在十六进制编辑器中被清除)。我怎样才能阻止 ie 进入怪癖模式?有什么办法吗?

回答by meder omuraliev

Try killing all the whitespace before the DOCTYPE.

尝试清除 DOCTYPE 之前的所有空白。

EDIT: There is an <feff>character which is a Unicode BOM signature at the start of the file. Since you may not have a text editor that can actually see that, try deleting the entire first line and paste over it with

编辑:<feff>文件开头有一个字符是 Unicode BOM 签名。由于您可能没有可以实际看到的文本编辑器,请尝试删除整个第一行并粘贴

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

And do NOT save the file with a BOM unicode signature. If this doesn't work, try a different text editor altogether.

并且不要使用 BOM unicode 签名保存文件。如果这不起作用,请完全尝试不同的文本编辑器。

回答by Pugazh

Paste the below code within the head tag

将以下代码粘贴到 head 标签中

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

回答by Amr

Quirks mode in any version of IE will also be triggered if anything precedes the DOCTYPE. For example, if a hypertext document contains a comment, space or any tag before the DOCTYPE declaration, IE will use quirks mode:

如果在 DOCTYPE 之前有任何内容,任何版本的 IE 中的 Quirks 模式也将被触发。例如,如果超文本文档在 DOCTYPE 声明之前包含注释、空格或任何标记,则 IE 将使用 quirks 模式:

<!-- This comment will put IE 6, 7, 8, and 9 in quirks mode -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

回答by Jon

I added both the doctype from the first comment and then the meta tag and it worked thanks guys .... and no thanks to IE :(

我添加了第一条评论中的文档类型,然后添加了元标记,它起作用了,谢谢大家......而且不感谢 IE :(

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

and

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

I have just changed the doctype to html5 and it still works great

我刚刚将 doctype 更改为 html5,它仍然很好用

 <!DOCTYPE html> 
    <html>
      <head> 
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">