背景:调试公司项目网页样式的时候,发现前人写的样式 是 .class1.class2 的样子,感觉还是中间加个空格比较好看,这一改不要紧,页面乱了。乱了。。。
但是,本菜鸡怎么能轻言放弃呢,先把东西还原回去(嘿嘿)。然后写个小总结。就在下面。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.c1 {
width : 100px;
height : 100px;
background: greenyellow;
}
.c1 .c1_1{
width : 30px;
height : 30px;
margin: 10px;
background: gainsboro;
}
/**
.c1 .c1_1.c1_2 {
width: 20px;
height: 20px;
margin : 10px;
background: black;
} */
</style>
</head>
<body>
<div class="c1">
<div class="c1_1"></div>
<div class="c1_1 c1_2"></div>
</div>
</body>
</html>
效果是这样的
放开注释,效果是这样的
**
可以看出,“ . ” 选择器之前有空格 取得是 子元素 , “.” 选择器之前没有空格 取得是 同时拥有这两种class的元素。
**