IE7以为是IE8?
我正在尝试使用条件注释来破解 IE7,使其表现得像真正的浏览器一样。
但最近几天,IE7 忽略了引用它的条件,只响应针对 IE8 的条件。
我的标题有:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
...
条件是:
<!--[if IE 7]>
<link rel="stylesheet" href="/css/ieHacks.css" type="text/css" media="screen" />
<![endif]-->
IE7 或 8 中都无法识别。但如果是
<!--[if IE 8]>
<link rel="stylesheet" href="/css/ieHacks.css" type="text/css" media="screen" />
<![endif]-->
则样式表会在 IE7 和 IE8 中呈现。
有什么想法吗?我很困惑。
I'm trying to use conditional comments to hack IE7 into behaving like a real browser.
But the last few days, IE7 is ignoring conditionals referencing it, and responding only to conditionals targeting IE8.
My header has:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
...
The conditionals are:
<!--[if IE 7]>
<link rel="stylesheet" href="/css/ieHacks.css" type="text/css" media="screen" />
<![endif]-->
Which is NOT recognized in either IE7 or 8. But if it's
<!--[if IE 8]>
<link rel="stylesheet" href="/css/ieHacks.css" type="text/css" media="screen" />
<![endif]-->
Then the stylesheet is rendered in both IE7 and IE8.
Any ideas? I'm stumped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了 IE8 无法读取 IE 样式表的问题,所以现在我更愿意在我的主样式表上添加 IE 的类。无论如何,使用一个样式表维护代码会更容易。 Paul Irish解释得更好但基本上你把这个:
条件样式表链接所在的位置,然后在 css 中为您需要的每个特定于 IE 的更改添加 ie 类。假设您的内边距通常为 6px,但对于 IE,您需要将其设置为 4px,该 div 的 css 如下所示:
I've had problems with IE8 not reading the IE stylesheet, so now I prefer to add a class for IE on my main stylesheet. It is easier to maintain code with one stylesheet anyway. Paul Irish explains it better but basically you put this:
where your conditional stylesheet link was and then in your css you add the ie class for every IE-specific change you need. So let's say your padding is normally 6px but for IE you need it to be 4px, your css for that div would look like:
您还可以使用 CSS hack 仅从主样式表中定位 IE7:
You could also use a CSS hack to target IE7 only from within your main stylesheet: