我创建了一个网页(http://www.snow4life.yum.pl),它在 Firefox、chrome 等中正确呈现。当然愚蠢的 IE 复杂的事情,因为它自动进入怪癖模式,即使正确设置了 doctype 和站点通过w3 验证(有一个错误是缺少一些字符,但文件已在十六进制编辑器中清除)。如何阻止 ie 进入怪癖模式?有什么办法吗?
4 回答
Try killing all the whitespace before the 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
<!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.
将以下代码粘贴到 head 标签中
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
如果在 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">
我从第一条评论中添加了文档类型,然后添加了元标记,它起作用了,谢谢大家....不感谢 IE :(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
和
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
我刚刚将文档类型更改为 html5,它仍然很好用
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">