css选择器 - 空格,无空格和大于号的区别 个人笔记
作者:互联网
无空格,选择的元素既有.box类,也有.p类
<style>
.box.p{
font-weight:bold;
color:red;
}
</style>
<body>
<div class="box">
<div class="p">
1
</div>
<div class="p2">
2
<div class="p">
3
<div class="box p">
4
</div>
</div>
</div>
</div>
</body>
有空格,选择.box下含有.p的子节点,子包括儿子节点、孙子节点
<style>
.box .p{
font-weight:bold;
color:red;
}
</style>
<body>
<div class="box">
<div class="p">
1
</div>
<div class="p2">
2
<div class="p">
3
<div class="box p">
4
</div>
</div>
</div>
</div>
</body>
大于号,选择.box下含有.p的子节点
<style>
.box>.p{
font-weight:bold;
color:red;
}
</style>
<body>
<div class="box">
<div class="p">
1
</div>
<div class="p2">
2
<div class="p">
3
<div class="box p">
4
</div>
</div>
</div>
</div>
</body>
标签:box,大于号,weight,color,选择器,空格,节点,red 来源: https://blog.csdn.net/Amnesiac666/article/details/122089575