CSS 中的高级选择器
cssweb developmentfront end technology更新于 2025/12/11 2:52:17
CSS 中的高级选择器包括相邻兄弟选择器、属性选择器、直接子选择器、第 n 个类型选择器等。它还包含通用兄弟选择器,示例如下:
h1 ~ h3
直接子选择器示例 −
div > span
以下是 CSS 中高级选择器的代码 −
示例
<html>
<head>
<style>
#red {
color: red;
}
.green {
background: green;
}
ul:nth-of-type(1) {
background: rgb(0, 174, 255);
}
ul + h3 {
border: 4px solid rgb(19, 0, 128);
}
a[href="https://www.wikipedia.org"] {
font-size: 25px;
}
h1 ~ h3 {
font-size: 40px;
}
div > span {
background-color: DodgerBlue;
}
</style>
</head>
<body>
<h1>Advanced Selectors Example</h1>
<ul>
<li>Cow</li>
<li>Dog</li>
<li>Cat</li>
</ul>
<ul>
<li>Puma</li>
<li>Leopard</li>
<li>Cheetah</li>
</ul>
<h3>Animals</h3>
<div>
<span>Text sample</span>
<p>
Paragraph Text
<span>span text</span>
</p>
<p class="green">Paragraph Text</p>
<p id="red">Paragraph Text.</p>
<p class="green">Paragraph Text</p>
</div>
<a href="https://www.google.com">www.google.com</a>
<a href="https://www.wikipedia.org" target="_blank">www.wikipedia.org</a>
</body>
</html>
输出
上述代码将产生以下输出 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

