可以使用 :empty 选择器来设置完全没有子元素或文本的元素的样式:
<div class="wrapper">
<div class="box"></div>
<div class="box">白日依山尽,黄河入海流。欲穷千里目,更上一层楼。</div>
</div>
.wrapper {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.box {
display: inline-block;
background: #999;
border: 1px solid #585858;
height: 200px;
width: 200px;
margin-right: 15px;
}
.box:empty {
background: #fff;
}
这也是一种方式