例如,我有如下HTML:
<div class='page'> <span>2</span> <span>2</span> <a>1</a> <a>6</a> </div>
第一个孩子怎么样?
我这样用:.page a:first-child {color:red}
但它不运行。
解决方法
使用
first-of-type
而不是
first-child
.page a:first-of-type{ color:red; }
The :first-of-type CSS pseudo-class represents the first sibling of its type in the list of children of its parent element.
摘自MDN Documentation.你可以找到更多的细节&示例here.