<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS 组合选择符</title>
<style>
.line{
border-bottom: 1px solid red;
}
/*后代选取器(以空格分隔)*/
/*匹配所有该元素的后代元素。*/
.body1 p
{
background-color:red;
}
/*子元素选择器(以大于号分隔)*/
/*子元素选择器(Child selectors)只能选择作为某元素子元素的元素。*/
.body2>p
{
background-color:yellow;
}
/*相邻兄弟选择器(以加号分隔)*/
.body3 .box+p
{
background-color:green;
}
/*普通兄弟选择器(以破折号分隔)*/
.body4 .box~p
{
background-color:blue;
}
</style>
</head>
<body>
<div class="line body1">
<div class="box">
<p>I am in box </p>
<p>I am in box </p>
</div>
<p>I am outside of box</p>
<p>I am outside of box</p>
</div>
<div class="line body2">
<div class="box">
<p>I am in box </p>
<p>I am in box </p>
</div>
<p>I am outside of box</p>
<p>I am outside of box</p>
</div>
<div class="line body3">
<div class="box">
<p>I am in box </p>
<p>I am in box </p>
</div>
<p>I am outside of box</p>
<p>I am outside of box</p>
</div>
<div class="line body4">
<div class="box">
<p>I am in box </p>
<p>I am in box </p>
</div>
<p>I am outside of box</p>
<p>I am outside of box</p>
</div>
</body>
</html>
css组合选择符
最新推荐文章于 2023-12-12 09:35:39 发布