jQuery: n -child选择器在ie7中不工作



我有一个div的网格,不是所有的div都是等高的,我需要它们都正确地对齐。我使用了第n个子jQuery选择器(见下文)来选择每行的第一个div,并对其应用clear:both样式。这适用于ie8及以上以及chrome和safari,但在ie7中,它只是忽略第n子位,因此不应用我的css。

我在css3上使用jQuery,这样它就可以在ie7中工作-所以我对事实有点困惑,它不是…

查看自己的html http://jackbeck.co.uk/?portfolio=courses

jQuery代码头:

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('.project.small:nth-child(4n+1)').css("clear", "both");
    });
</script>'    

有人能帮忙吗?

是;IE8,下面是不支持nth-child的伪选择器。但如果你想要IE support你必须使用http://selectivizr.com/js

你的jQuery不工作,因为你使用$而不是jQuery(这是一个WordPress的事情)。试试这个:

<script type="text/javascript">
    jQuery(document).ready(function($){
        jQuery('.project.small:nth-child(4n+1)').css("clear", "both");
    });
</script>

jQuery选择器本身,事实上,在IE7中工作。这不是你的问题。你的问题与CSS有关

遗憾的是IE7不支持nth-child选择器

最新更新