CSS:first-child selector IE7 [英] CSS :first-child selector IE7

查看:208
本文介绍了CSS:first-child selector IE7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有小IE7问题。我有以下CSS代码,它不工作在IE7。但是,.row [class * =span]和:first-child都可以工作,如果他们没有组合。是否有办法做类似的事情或使其工作在某种方式?

I've got little IE7 issue. I've got following CSS code and it does not work in IE7. However, .row [class*="span"] and :first-child both work if they are not combined. Is there a way to do something similar or make it work somehow?

.row [class*="span"]:first-child {
    margin-left: 0;
}


推荐答案

>是 [class * =span] ,请检查它之前是否有HTML注释。如果存在, IE7会错误地认为该评论是第一个孩子,因此它将不匹配您的元素're寻找。

If the first child is [class*="span"], check to see if there's an HTML comment before it. If there is, IE7 will mistakenly think the comment is the first child, so it won't match the element you're looking for.

如果您无法更改标记以删除评论,您可以使用我描述的覆盖技术解决此处

If you can't change the markup to delete the comment, you can work around it using the override technique I describe here:

.row [class*="span"] {
    margin-left: 0;
}

.row [class*="span"] ~ [class*="span"] {
    margin-left: /* Reset the left margin for other elements */;
}

如果您不知道保证金值重置为,请尝试使用 * + html hack:

If you don't know the margin value to reset it to, you can try adding another selector that targets IE7's behavior with the * + html hack:

.row [class*="span"]:first-child, * + html .row :first-child + [class*="span"] {
    margin-left: 0;
}

:first-child + [class * = span] 匹配那个元素,如果它恰好跟在IE7中的第一个孩子的一个注释节点。

:first-child + [class*="span"] matches that element if it follows exactly one comment node that's the first child in IE7.

这篇关于CSS:first-child selector IE7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆