CSS 类在 IE7-8 中根本没有应用
已设置,并在每个页面的
中包含
html5shim.js
。
我将 CSS:
.height_fix_container > * { margin:0; background:#fff url(../images/bg.jpg) top left no-repeat; min-height: 400px; }
.height_fix_container > *:first-child { background:#fff; } /*Good eye! But the problem still exists*/
...应用于页面中间的代码:
...
<div class="height_fix_container">
<div>Content box 1</div>
<div>Content box 2</div>
</div>
...
在除 IE7 和 8 之外的每个浏览器中,CSS 选择器都工作得很好。但是,在 IE 中,内容框 1
可以识别选择器,但 内容框 2
完全忽略它。我正在使用 IE 中内置的开发人员工具检查这一点。
为什么会发生这种情况?
<!DOCTYPE html>
has been set, and html5shim.js
has been included in the <head>
of each page.
I have the CSS:
.height_fix_container > * { margin:0; background:#fff url(../images/bg.jpg) top left no-repeat; min-height: 400px; }
.height_fix_container > *:first-child { background:#fff; } /*Good eye! But the problem still exists*/
...being applied to this code in the middle of the page:
...
<div class="height_fix_container">
<div>Content box 1</div>
<div>Content box 2</div>
</div>
...
In every browser other than IE7 and 8, the CSS selectors work great. However, in IE Content box 1
recognizes the selector but Content box 2
completely ignores it. I'm checking this with the built in Developer Tools in IE.
Why might this be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 IE 中,您需要声明一个 DOCTYPE 才能识别第一个子选择器。
在第二个类定义中,您还缺少“fff”前面的#。它根本不影响代码,只是语法编辑。
http://www.w3schools.com/cssref/sel_firstchild.asp
In IE you need to have a DOCTYPE declared in order for it to recognize the first-child selector.
You're also missing a # infront of the 'fff' in the second class definition. It doesn't affect the code at all, just a syntactical edit.
http://www.w3schools.com/cssref/sel_firstchild.asp
IE7 对
:first-child
非常挑剔,可能会因为前面的*
而感到窒息。也许您可以向工作表添加另一种样式:
未测试
IE7 is very particular with
:first-child
and might be choking on the*
before it.Perhaps you can add another style to the sheet:
Untested
您的页面正在怪癖模式下显示。你的描述和 CSS 让我非常确定。
最可能的原因是您没有有效的文档类型作为第一行。添加以下内容:
如果您已经有了文档类型,则还有其他事情可能会导致怪异模式。
修复此问题后,
background:fff
将不再起作用。您需要背景:#fff
。#
很重要。Your page is being displayed in Quirks Mode. Your description and CSS is making me quite certain.
The most likely cause is that you don't have a valid doctype as the very first line. Add this:
If you do already have a doctype, there are other things can cause Quirks Mode.
Once you fix this,
background:fff
will no longer work. You needbackground:#fff
. The#
is important.http://jsfiddle.net/a256R/ - 类似的选择器 - 在 IE7 和 IE8 中工作(第一个 div 是绿色的,第二个是红色)。问题出在其他地方(背景图片 url、其他规则等)。
http://jsfiddle.net/a256R/ - similar selectors - work in IE7 and IE8 (first div is green, second is red). Problem is somewhere else (background image url, other rules etc.).