2013-08-18 50 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分配给第一个孩子,然后访问它。由于浏览器的兼容性。 –

相关问题