html - 我想设计一个容器,它可以容纳 3 个内联的 div,其中包含父属性
问题描述
在我的容器中,我放置了border-radius,但是每当我在容器内对齐3个div时,border-radius就会丢失。Container分为3部分,但它占据了容器的整个高度,并且我给出的border-radius丢失了在孩子之下。实际上,我希望孩子的左侧和右侧的孩子将半径上下。
HTML 代码:
.container {
width: 500px;
height: 200px;
border-radius: 7px;
background: black;
margin: 50px auto;
display: inline-block;
}
.child1 {
background: white;
height: 100%;
width: 33.3%;
float: left;
}
.child2 {
background: red;
height: 100%;
width: 33.3%;
float: left;
}
.child3 {
background: blue;
height: 100%;
width: 33.3%;
float: left;
}
<div class="container">
<div class="child1">
</div>
<div class="child2">
</div>
<div class="child3">
</div>
</div>
解决方案
添加overflow: hidden
到容器中。
.container {
width: 500px;
height: 200px;
border-radius: 7px;
overflow: hidden; /* this will enforce the appearance of border-radius */
background: black;
margin: 50px auto;
display: inline-block;
}
.child1 {
background: green;
height: 100%;
width: 33.3%;
float: left;
}
.child2 {
background: red;
height: 100%;
width: 33.3%;
float: left;
}
.child3 {
background: blue;
height: 100%;
width: 33.3%;
float: left;
}
<div class="container">
<div class="child1">
</div>
<div class="child2">
</div>
<div class="child3">
</div>
</div>
推荐阅读
- json - Swift Parsing 使用 1 个 url api 解码 2 个不同的 json
- r - 循环 df 并在 R 中创建新的 df
- javascript - 输入表单属性未连接到表单
- python - How to arrange nested subplots in Matplotlib?
- webrtc - 从哪里开始学习有关为音频视频发送 rtp 数据包的基础知识
- bash - 在 Bash 中拆分字符串以打印由“-”分隔的前两个字符
- mysql - Mysql 建表时语法错误 #1064
- html - Input/Set/Change HTML img src with Node JS
- excel - Change arrow color based on its label or value
- selenium - How to disable "Mark non-secure origins as non-secure" within selenium tests?