2013-08-18 82 views
2

如何訪問myabilities中的第一個元素,代碼如下?如何訪問myabilities類的第一個元素?

<div class="span6"> 
     <h3 class="srvc-title">Responsive Design</h3>    
     <p class="srvc-detail">Crafting great experiences to suit the capabilities of every browser.</p> 
     <p class="myabilities">The number of web-accessible devices is truly a wonder of our information age. It’s also a daunting canvas for design.</p> 
     <p class="myabilities">Mobile phones, tablets, desktops — it’s hard to even categorise these days. I specialise in embracing the Web’s ubiquity. It’s my job to design for all experiences.</p> 
     <p class="myabilities">Great design can’t be achieved in isolation. In fact, it’s two development practices that are the secret; feature detection and progressive enhancement. That means a multi-tiered design to match the capabilities of any browser.</p> 
     <p class="myabilities">Complicated for us but for users — it just works.</p> 
</div> 
+1

這裏是[理由](http://stackoverflow.com/a/18298969/1725764 )爲什麼你不能像':nth-​​child'或':first-of-type'那樣使用CSS3僞類來做到這一點。 –

+0

[CSS3選擇器:類名的第一個類型?]的可能的重複(http://stackoverflow.com/questions/6447045/css3-selector-first-of-type-with-class-name) – Adrift

回答

1

不幸的是僞類,如:nth-child:nth-of-type只會看基於他們type,不是他們的類或ID值,就像你可能期待的元素。但考慮到您的加價(假設它不會改變),你可以選擇使用:

div.span6 .srvc-detail + p { 
    color: gold; 
} 

http://jsfiddle.net/E3GSV/3/

+2

'div .span .srvc-detail + p'更好,不是嗎? –

+0

事實上,我忽略了這一點。謝謝! – Adrift

+1

謝謝你......我明白了,但現在不是使用css3選擇器。我只是將id分配給第一個孩子,然後訪問它。由於瀏覽器的兼容性。 –

相關問題