层次选择器
演示代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
/*后代选择器*/
/* body p{
background: aqua;
}*/
/* 子选择器 */
/*body>p{
background: bisque;
}*/
/* 相邻兄弟选择器 只向下一个同级别的不包含自身 不向上 */
/*.xc + p {
background: blueviolet;
}
.xc1 + li {
background: aquamarine;
}*/
/* 通用兄弟选择器 向下同级别的所有 不包含自身 */
.xc~p{
background: blueviolet;
}
</style>
<body>
<p>p0</p>
<p class="xc">p1</p>
<p>p2</p>
<p>p3</p>
<ul>
<li><p>p4</p></li>
<li class="xc1"><p >p5</p></li>
<li><p >p6</p></li>
</ul>
</body>
</html>
介绍:
1.后代选择器: 在某个元素后面 比如 祖爷爷 爷爷 爸爸 你
/*后代选择器*/
body p{
background: aqua;
}
2.子选择器 : 一代 儿子
/* 子选择器 */
/*body>p{
background: bisque;
}*/
3.相邻兄弟 选择器 同辈 只选择同级别向下一个 不包含自身
/* 相邻兄弟选择器 只向下一个同级别的不包含自身 不向上 */
/*.xc + p {
background: blueviolet;
}
.xc1 + li {
background: aquamarine;
}*/
4.通用兄弟选择器 当前选中元素同级别向下所有元素 不包含自身
/* 通用兄弟选择器 向下同级别的所有 不包含自身 */
.xc~p{
background: blueviolet;
}