css - 如何仅使用 css 设置挤压框的样式
问题描述
我正在考虑如何设计一个像这样的挤压框:
我发现我可以使用伪元素和边框半径作为百分比来实现类似的结果。这是 CodePen:https ://codepen.io/micu22/pen/eYzpmqR 这是代码:
div {
background: lightblue;
padding: 10px 20px;
border-radius: 8px;
position: relative;
}
div::after,
div::before {
content: "";
position: absolute;
background: white;
width: 100%;
height: 20px;
left: 0;
}
div::before {
top: -17px;
border-radius: 50%;
}
div::after {
bottom: -17px;
border-radius: 50%;
}
但也许有更简单或更优雅的解决方案?
解决方案
我会这样做,使用渐变着色和 SVG 过滤器:
.box {
width:200px;
height:250px;
background:
/* v-- adjust the 15% here */
radial-gradient(50% 15% at top, transparent 98.5%,lightblue) top,
radial-gradient(50% 15% at bottom,transparent 98.5%,lightblue) bottom;
background-size:100% 51%;
background-repeat:no-repeat;
filter: url('#goo');
}
<div class="box"></div>
<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs> <!-- adjust the the 13 here --v -->
<filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="13" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop"/>
</filter>
</defs>
</svg>
推荐阅读
- c# - 我尝试连接到 Heidisql 时出现服务器版本错误
- javascript - 存储目标元素兄弟的内部 html
- python - Numpy Slicing - 从 3x3 数组计算矩阵 PseudoInverses 而无需迭代
- mysql - 我可以使用什么正则表达式来匹配字符串的百分比?
- r - 部分匹配的字符串分割向量
- javascript - 从选择框选项中获取值后如何提交
- r - 选择了 R 样本拆分列
- c# - 将脚手架项目添加到 asp.net Core App 时遇到问题
- couchbase - 从 Couchbase 获取每个文档类型的样本
- javascript - SharePoint 的 Stratus 表单。单击提交按钮后比较输入