試一試
dt {
font-weight: bold;
}
dd {
margin: 3px;
}
dd:nth-last-of-type(3n) {
border: 2px solid orange;
}
<dl>
<dt>Vegetables:</dt>
<dd>1. Tomatoes</dd>
<dd>2. Cucumbers</dd>
<dd>3. Mushrooms</dd>
<dt>Fruits:</dt>
<dd>4. Apples</dd>
<dd>5. Mangos</dd>
<dd>6. Pears</dd>
<dd>7. Oranges</dd>
</dl>
語法
css
:nth-last-of-type(<An+B> | even | odd) {
/* ... */
}
引數
:nth-last-of-type() 偽類透過一個引數指定,該引數表示從末尾開始匹配元素的模式。
有關其語法的更詳細解釋,請參閱:nth-last-child。
示例
HTML
html
<div>
<span>This is a span.</span>
<span>This is another span.</span>
<em>This is emphasized.</em>
<span>Wow, this span gets limed!!!</span>
<del>This is struck through.</del>
<span>Here is one last span.</span>
</div>
CSS
css
span:nth-last-of-type(2) {
background-color: lime;
}
結果
規範
| 規範 |
|---|
| 選擇器 Level 4 # nth-last-of-type-pseudo |
瀏覽器相容性
載入中…