使用元素 ~ 元素選擇器選擇 元素,前面是
元素。您可以嘗試運(yùn)行以下代碼來(lái)實(shí)現(xiàn)此示例
示例
實(shí)時(shí)演示
<!DOCTYPE html>
<html>
<head>
<style>
p~ul {
color: white;
background-color: blue;
}
</style>
</head>
<body>
<h1>Demo Website</h1>
<h2>Fruits</h2>
<div>
<p>Vegetables are good for health.</p>
<ul>
<li>Spinach</li>
<li>Onion</li>
<li>Capsicum</li>
</ul>
</div>
<p>Fruits are good for health.</p>
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Kiwi</li>
</ul>
</body>
</html>
登錄后復(fù)制
以上就是選擇前面有 CSS 元素的每個(gè)元素的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!






