简体   繁体   中英

IE7 thinks it is 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.

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;}

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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