html - 如何仅在底部创建一个带有边框和半径的 div,在另一个带有边框和半径的 div 内
问题描述
我需要一个具有盒子机智的组件,border
并且border-radius
在该组件内部,我需要一个带有border
* 和border-radius
底部的标题。
我写这个小提琴是为了更好地理解: 小提琴
编码:
border-1 {
width: 100px;
height: 100px;
background-color: #ccc;
margin: 50px;
border: 1px solid black;
display: flex;
border-radius: 3px;
}
border-2 {
flex: 1 1 auto;
border: 1px solid black;
height: 30px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
<border-1>
<border-2>
</border-2>
</border-1>
预期结果:
但是有时我在添加一些填充或出现滚动条时会得到这个:
有人可以解释我为什么吗?谢谢。
解决方案
用于position:relative
父母和position:absolute
孩子
还添加到子项width:calc(100% - 2px);
(-2px
:1px
用于边界右边+
1px
界左边界)
border-1 {
width:100px;
height:100px;
background-color:#ccc;
margin:50px;
border:1px solid black;
display:flex;
border-radius: 3px;
position:relative;
}
border-2 {
flex:1 1 auto;
border:1px solid black;
height: 30px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
position:absolute;
width:calc(100% - 2px);
}
<border-1>
<border-2>
</border-2>
</border-1>
推荐阅读
- python-3.x - 如何使用python从文本中删除单个或多个问号
- snowflake-schema - 如何仅检索雪花视图或表格上的评论
- django - 为什么 django 会抛出像“'function' object has no attribute 'order_set'”这样的错误?
- javascript - 文件下载完成后调用 JavaScript 函数 ASP.NET MVC
- html - 在本地主机上运行转换后的 wp 站点
- c++ - 如何在代码中找到所有悬空指针?
- c++ - __memory_barrier 的标准 C++ 等效项
- ssh - SELinux:命令输出打印在串行而不是 ssh
- oracle - 无法验证 - 未找到父键
- rust - 锈 | 为什么当我创建新的哈希映射时它给了我错误