CSS Selector for first nested element with class

时间:2018-03-23 00:50:10

标签: html css html5 css-selectors

Trying to select the first instance of an element of class 'vidplayicon' in each 'imgClass' div.

here is my HTML

<div class="imgClass">
  <div>
    <p>test</p>
  </div>
  <div>
    <p class="vidplayicon">test</p> <!-- this should be selected-->
  </div>
  <div>
    <p class="vidplayicon">test</p>
  </div>
</div>
...
<div class="imgClass">
  <div>
    <p class="vidplayicon">test</p> <!-- this should be selected-->
  </div>
  <div>
    <p class="vidplayicon">test</p>
  </div>
  <div>
    <p class="vidplayicon">test</p>
  </div>
</div>

and this is my CSS

.imgClass  div .vidplayicon:first-of-type{
    color:red;
}

but it's not working can I have some suggestions?

1 个答案:

答案 0 :(得分:0)

它首先用于标记名称,而不是类。

查看this thread.