有沒有辦法選擇最後一次出現的特定元素與CSS?如何選擇頁面中的最後一個元素?
這是一個例子:DEMO
我想last-child
但這不是我想要的。我用這個類:
HTML:
<ul>
<li><span>test</span></li>
<li>
<span>test</span>
<span>test</span>
</li>
</ul>
<div>
<span>test</span>
<span>test</span>
</div>
<p>
<span>test</span>
<span>red</span>
</p>
CSS:
span:last-child{
color:red;
font-weight:bold;
}
我想最後span
與 「紅色」 的內容是紅色的。我怎麼可以用CSS來做到這一點?
更新: 有一個解決方案與last-of-type
元素與父母相同。但是不同的父母呢?
你試過['最後的-type'(https://開頭開發商。 mozilla.org/en-US/docs/Web/CSS/lastlast-of-type),注意這是一個css3選擇器,不可用在IE下面9 –
@PatrickEvans我該怎麼試試這個?像'*:最後一個範圍:最後一個孩子'? –
它是一個僞類,像'最後一個孩子','跨度:最後一個類型' –