IE7 ignores CSS attribute selector only on pages c

2019-03-17 14:16发布

On my website, IE7 seems to be ignoring certain CSS attribute selectors. The strange thing is that it only happens when the page comes from the production server. If I have the exact same code on my personal server, or saved on my hard drive, it works fine. Here is an example which causes the problem:

<!DOCTYPE HTML>
<html><head>
<title>IE display test</title>
<style type="text/css">
[type=button] {
  display: block;
}
</style>
</head>
<body>
<input type="button" value="Button 1"/>
<input type="button" value="Button 2"/>
<input type="button" value="Button 3"/>
</body></html>

Since the display on the buttons is set to "block", they should be arranged vertically. But only when the page is served from my production server, they are arranged horizontally. When I use the developer toolbar to inspect the style, I don't see the "display" property like I usually do. The only thing I can think of that would possibly cause this is the URL of the page or the response headers coming from the server. I can maybe figure it out by experimenting but that would be inconvenient and time-consuming so before I do that, I would like to ask: Why is this happening and what can be done about it?

EDIT: I came up with a Fiddle. It looks fine on that site.

EDIT 2: Here are the response headers coming from the production server:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en-US
Content-Length: 291
Date: Wed, 18 Jan 2012 21:32:48 GMT

EDIT 3: Here are the response headers from my personal server:

HTTP/1.1 200 OK
Date: Wed, 18 Jan 2012 21:37:30 GMT
Server: Apache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 176
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: text/html;charset=utf-8

The production server is not applying gzip compression because it only does that for files above a certain size. If I add some stuff to make the file big enough, it uses gzip and I still see the problem in IE7, so this does not seem to have anything to do with gzip.

I tried configuring my personal server to send a "Content-Language" header like the production server and that did not trigger the problem.

I don't know if any of the other headers have anything to do with this. I can try testing them but it will be kind of tricky so it may take some time.

EDIT 4: I don't notice this problem in IE8, even if I turn on compatibility mode. I am testing this on Windows XP, in case that matters.

EDIT 5: I put the charset in the Content-Type header from my personal server. It didn't trigger the problem.

EDIT 6: Here are some screenshots: Served from the production server: IE7 test on production server

Served from my personal server: IE7 test on personal server

Loaded directly from my hard drive: IE7 test directly from my hard drive

EDIT 7: I finally got a clue as to what is causing this! I tried entering javascript:alert(document.compatMode) into the address bar. The personal and direct pages showed CSS1Compat but the production page showed BackCompat. It seems like the browser is in quirks mode only when it is rendering the page from the production server. So far, I have no idea why this is happening or what to do about it.

EDIT 8: I left out a detail: The screenshot is actually from my dev environment, which is emulating the production server but running on my own computer. That would make BoltClock's reply seem plausible, except for the fact that the same problem is showing up on our actual production server, which is on an IP address matching 173...*. Why do I see the problem on that server? Is that also a private IP address? It may be helpful to know that the actual production server is using https.

EDIT 9: Since the bounty expired, the problem stopped showing up on the production server but it still shows up in my dev environment (10.1.10.34). I have no idea why. I think I will blame it on cosmic rays unless I can come up with some more evidence.

7条回答
冷血范
2楼-- · 2019-03-17 14:36

I don't think the answer is which server it came off but more a case of adding double quotes around the value in the CSS selector.

Try this:

<!DOCTYPE HTML>
<html><head>
<title>IE display test</title>
<style type="text/css">
[type="button"] {
  display: block;
}
</style>
</head>
<body>
<input type="button" value="Button 1"/>
<input type="button" value="Button 2"/>
<input type="button" value="Button 3"/>
</body></html>
查看更多
Animai°情兽
3楼-- · 2019-03-17 14:40

I get a feeling it has something to do with the server (Based on the apache/coyote I guess you're using tomcat?) and either something to do with whitespaces, or BOF, or improper utf-8 setting (i've heard of issues where header claims to be utf-8 but isn't). If you have any whitespace before the html declaration, that might also trigger it to go into quirks mode. While I may be wrong, I get the feeling that your problem is similar to this one Why is ie7 always in Quirks mode?

查看更多
我命由我不由天
4楼-- · 2019-03-17 14:41

As discussed in the comments, according to this answer by thirtydot and this answer by scunliffe, it seems very likely to be the effect of a security feature in Internet Explorer. Your production server lives within your intranet, and is being accessed via a private, class A IPv4 address (10.*.*.*), which I suspect basically causes IE7 to render pages in quirks mode (and IE8 and newer to render pages in Compatibility View).

All this is just a guess, though, I'm afraid — I haven't been able to reproduce your problem in any IE browser on any system, at least not on your personal server or with my own files. If your production server is open to public access, not just technically, perhaps you could provide a link to it so we can debug further, as the problem is obviously localized to just your production server.

查看更多
放荡不羁爱自由
5楼-- · 2019-03-17 14:47

I just played around with the code on your personal server (eliasz.net), a file served through the file:// protocol, and served on a local server.

Your personal server and when rendered through the file:// protocol are both rendering correctly as they are rendered in 'edge' mode (the latest, rather than compatibility mode). However, on your production server and on your development server, they are rendering in compatibility mode. As BoltClock said, intranets do this by default. Obviously, this would apply for your development server (on a local IP like 10.1.10.34).

I think the production server is also on your local network, although it has a public static IP. In other words, when you are on the local network, the production server is served through the local network, not the internet. Hence, IE7 still sees it as an intranet site. Use nslookup to check how IE7 is resolving the domain name.

To get round the issue, you can add this to your header:

<meta http-equiv="X-UA-Compatible" content="IE=9" >

and then turn off the setting in your IE that causes it to render intranet sites in compatibility mode.

查看更多
ら.Afraid
6楼-- · 2019-03-17 14:49

I see that one page is .html and the other is .php. It might be possible that your php page has some character (maybe hidden) before the doctype. It could make a difference on how IE accepts HTML and CSS.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-03-17 14:50

I just ran into this with both IE8 and IE9 and I found the solution!

Now this may not translate exactly to IE7, but it should point you in the right direction.

  • Look through the menus for an item called "Compatibility View".
  • Give it a click and it opens a dialog where you can add websites to be shown in "Compatibility View".
  • Look below the list for a check box labeled "Display intranet sites in Compatibility View"
  • Uncheck it.

It appears that Microsoft considers a host part of the "intranet" when it is:

  • joined to the same domain,
  • identified by an unqualified host name (ex "server" vs "server.example.com"), or
  • identified by a private IP address (10.x.x.x, 172.16-31.x.x, 192.168.x.x)

It also looks like nothing is considered "intranet" if the client system is not joined to a domain.

查看更多
登录 后发表回答