<div class="demo">
<div class="first box">名稱只有 "first"</div>
<div class="second box">名稱只有 "second"</div>
<div class="first second box">名稱同時具有 "first" 和 "second" </div>
<div class="first box">
<div class="second">名稱為 "second",階層於名稱為 "first" 的div之下 </div>
</div>
<div class="second box">
<div class="first">名稱為 "first" ,階層位於名稱為 "second" 的div之下 </div>
</div>
</div>
/* 指定 first 裡面的 second 才會顯示黑色*/
.first .second{
background-color: black;
color: white;
height: auto;
}
/* CSS For Decoration */
html, body{
font-family: "微軟正黑體";
font-weight: bold;
}
.demo{
display: ;
height: 50vh;
justify-content: space-around;
}
.box{
width: 150px;
height: 70px;
margin: auto;
border: 2px solid #000;
border-radius: 5px;
text-align: left;
padding: 10px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.