IE7以为是IE8?

发布于 2024-12-14 13:30:36 字数 867 浏览 6 评论 0原文

我正在尝试使用条件注释来破解 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲欢浪云 2024-12-21 13:30:36

我遇到了 IE8 无法读取 IE 样式表的问题,所以现在我更愿意在我的主样式表上添加 IE 的类。无论如何,使用一个样式表维护代码会更容易。 Paul Irish解释得更好但基本上你把这个:

<!--[if IE]> <html class="ie"> <![endif]-->

条件样式表链接所在的位置,然后在 css 中为您需要的每个特定于 IE 的更改添加 ie 类。假设您的内边距通常为 6px,但对于 IE,您需要将其设置为 4px,该 div 的 css 如下所示:

.someClass {padding: 6px;}
.ie .someClass {padding: 4px;}

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:

<!--[if IE]> <html class="ie"> <![endif]-->

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:

.someClass {padding: 6px;}
.ie .someClass {padding: 4px;}
小嗷兮 2024-12-21 13:30:36

您还可以使用 CSS hack 仅从主样式表中定位 IE7:

*:first-child+html { /* Apply IE7-only CSS here */ }

You could also use a CSS hack to target IE7 only from within your main stylesheet:

*:first-child+html { /* Apply IE7-only CSS here */ }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文