Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:
:nth-of-type()
针对具有一组兄弟节点的标签, 用 n 来筛选出在一组兄弟节点的位置。
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
ul li:nth-of-type(4){
background-color: red;
}
ul li:nth-of-type(1n){
background-color: red;
}
ul li:nth-of-type(n+4){
background-color: red;
}
ul li:nth-of-type(2n){
background-color: red;
}
或使用关键字(even)
ul li:nth-of-type(even){
background-color: red;
}
ul li:nth-of-type(2n+1){
background-color: red;
}
或使用关键字(odd)
ul li:nth-of-type(odd){
background-color: red;
}
ul li:first-of-type{
background-color: red;
}
ul li:last-of-type{
background-color: red;
}
:nth-last-of-type()
)
ul li:nth-last-of-type(-n+3){
background-color: red;
}
ul li:nth-last-of-type(3){
background-color: red;
}
:only-of-type