css - 纯 CSS 同级选择器
问题描述
<style>
#b2-Column1 {
background-color:red;
min-height:120px;
}
#b2-Column1 > div {
background-color:yellow;
min-height:100px;
}
</style>
<div id="b2-Column1">
<div><!-- some comments here's --></div>
</div>
我该怎么办,如果黄色部分是空的,那么我想将红色和黄色设置为显示:无;
解决方案
你能做的最好的就是用:empty
伪类隐藏黄色部分,但是,由于我们没有父选择器,你必须为红色部分寻找 JavaScript 解决方案。
.container {
background-color: red;
min-height: 120px;
margin-top: 1em;
}
.child {
background-color: yellow;
min-height: 100px;
}
.child:empty {
display: none;
}
<div class="container">
<div class="child"><!-- some comments here's --></div>
</div>
<div class="container">
<div class="child">
<p></p>
</div>
</div>
推荐阅读
- javascript - 为什么我不能将注销按钮移到右侧
- python-3.x - 我需要根据其中一列的唯一值从巨大的数据框中获取多行
- javascript - 从具有多个对象的数组中获取数据
- android - 片段崩溃中的 setImageRessource(R.drawable.image)
- android - 当我启动 Android Emulator 时,我的 Mac 桌面上的音频停止
- amazon-web-services - 我可以在状态机定义文件中使用全局变量吗?
- opencv - 如何确定 ArUco 标记板的中心坐标?
- mule - 如何映射数组的某些键以在 mule 4 中创建另一个键
- android - Volley 给出超时错误,但数据已发送到服务器?
- python - 将 python PDF 生成器库与 Angular 集成