简体   繁体   English

IE7认为是IE8吗?

[英]IE7 thinks it is IE8?

I'm trying to use conditional comments to hack IE7 into behaving like a real browser. 我正在尝试使用条件注释来使IE7像真实的浏览器一样运行。

But the last few days, IE7 is ignoring conditionals referencing it, and responding only to conditionals targeting IE8. 但是最近几天,IE7忽略了引用它的条件语句,只响应了针对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 IE7或8无法识别哪个。但是如果

<!--[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. 然后在IE7和IE8中都呈现样式表。

Any ideas? 有任何想法吗? I'm stumped. 我很沮丧

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. 我遇到了IE8无法读取IE样式表的问题,因此现在我更喜欢在主样式表上添加IE的类。 It is easier to maintain code with one stylesheet anyway. 无论如何,使用一个样式表来维护代码更容易。 Paul Irish explains it better but basically you put this: 保罗·爱尔兰(Paul Irish) 对此做了更好的解释,但基本上您可以这样说:

<!--[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. 条件样式表链接所在的位置,然后在CSS中为需要的每个特定于IE的更改添加ie类。 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: 因此,假设您的填充通常为6px,但对于IE,您需要将其填充为4px,该div的css如下所示:

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

您还可以使用CSS hack仅从您的主要样式表中将IE7作为目标:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM