2013-04-12 19 views
1

第一個元素的CSS選擇器我有這個東西的內部

<div class="foo"> 
    <input type="text" name="bar" value="" /> 
    <a href="javascript:void(0)">foobar 1</a> 
</div> 
<div class="foo"> 
    <input type="text" name="bar" value="" /> 
    <a href="javascript:void(0)">foobar 2</a> 
</div> 
<div class="foo"> 
    <input type="text" name="bar" value="" /> 
    <a href="javascript:void(0)">foobar 3</a> 
</div> 

<!-- I'm trying with this CSS, but with no luck --> 
<style> 
.foo a:first-child { 
    display:none; 
} 
</style> 

我怎麼只能顯示foobar 2foobar 3鏈接?

回答

4

選擇器應選擇第一.foo元素,而不是foo中第一a

.foo:first-child a{ 
    display:none; 
} 

對僞選擇以及更多的信息,這working examplethis post

1

你應該將:first-child僞類:

.foo:first-child a { 
    display:none; 
} 

但它要求div是第一個孩子它的父元素。

DEMO

+0

工作!謝謝 –

-1

這麼簡單

$('.foo:nth-child(3)')