我正在尝试为第一个带有类名 "unit" 的 <div>
添加底部边距。
<div id="wrapper-related-albums">
<div class="header">...</div>
<div class="unit">...</div> //add margin-bottom to this one!!!!
<div class="header">...</div>
<div class="unit">...</div>
</div>
#wrapper-related-albums .unit:first-child {margin-bottom:20px;} // doesn't work!!!
#wrapper-related-albums .unit:first-of-type {margin-bottom:20px;} // doesn't work!!!
:first-of-type
只能在元素选择器上工作,不能在类上工作。为什么需要在此元素中添加底部边距? - cimmanon:first-of-type
查找其父元素的子元素列表中,是其类型的第一个同级元素;而:first-child
则表示某个其他元素的第一个子元素——属性会被忽略。 - Adrift