html - 隐藏在容器上的 CSS 边框半径和溢出使内容渗透 1 px
问题描述
我有以下代码:
https://jsfiddle.net/uq2018xv/3/
body {
background: black;
font-family: sans-serif;
}
.container {
height: 200px;
width: 200px;
border-radius: 100%;
overflow: hidden;
position: relative;
}
.container>img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.container>span {
background: #2b2b2c;
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 0pt 0 2pt;
text-align: center;
font-weight: 600;
font-size: 20pt;
color: white;
}
<div class="container">
<img src="https://images.unsplash.com/flagged/photo-1593005510329-8a4035a7238f?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80">
<span>EDIT</span>
</div>
内容在底部渗透 1px。有没有办法解决这个问题,让它看起来更干净?
解决方案
我想出了解决方案。通过设置:
clip-path: inset(0px 0px HEIGHT_OF_EDIT_SPAN 0px);
在图像上。
其中 HEIGHT_OF_EDIT_SPAN 是底部 EDIT 跨度的高度。
所以它会在底部剪辑图像,但仍然保持图像居中。
推荐阅读
- javascript - 如何让 Quokka.js 识别本地模块
- amazon-web-services - 如何在 AWS 任务定义中指定磁盘空间?
- javascript - TypeError:无法读取未定义错误的属性“来自”
- python - Python 前缀后缀中缀,无括号
- react-native - react-native run-android VS ./gradlew assembleDebug
- php - 运行 Laravel Dusk 时没有输出/什么也没有发生
- javascript - 根据按钮单击动态更改 iframe 大小
- matlab - 检查结构的字段是否为空,然后为其分配默认值
- javascript - 使用 BFS (javascript) 查找最短路径未加权图
- bash - bash 命令在控制台中运行,但不在脚本中