css - 在css中,如何创建一个凸出的正方形
解决方案
这是一个简单的例子,我们改变了 top 和 bottom border-radius
es。我们可以使用另一个值作为一种奇怪的高度来控制我们半径的高度。
.box {
background: #62f;
color: white;
border-radius: 50% / 10px;
padding: 30px;
width: 1em;
height: 1em;
}
<div class="box">8</div>
现在,我们可以使用::before
and::after
选择器来制作其中的两个:
.box::after {
background: #62f;
color: white;
border-radius: 50% / 10px;
padding: 30px;
width: 1em;
height: 1.75em;
content: "";
display: block;
position: absolute;
top: 2px;
left: 8px;
}
.box::before {
background: #62f;
color: white;
border-radius: 10px / 50%;
padding: 30px;
width: 1.75em;
height: 1em;
content: "";
display: block;
position: absolute;
top: 8px;
left: 2px;
}
<div class="box">8</div>
那么,我听到你问,我们的 8 呢?它去哪儿了?好吧,我的朋友们,它实际上已经在我们奇怪的广场后面了。我们可以将它包装在一个跨度中并设置它的样式来解决这个问题。
.box::after {
background: #62f;
color: white;
border-radius: 50% / 10px;
padding: 30px;
width: 1em;
height: 1.75em;
content: "";
display: block;
position: absolute;
top: 2px;
left: 8px;
}
.box::before {
background: #62f;
color: white;
border-radius: 10px / 50%;
padding: 30px;
width: 1.75em;
height: 1em;
content: "";
display: block;
position: absolute;
top: 8px;
left: 2px;
}
.box > span {
position: absolute;
top: 32px;
left: 36px;
z-index: 5;
color: white;
font-size: 1.5em;
font-family: sans-serif;
}
<div class="box"><span>8</span></div>
我们还可以交换一些数字以使其更加完美:
.box::after {
background: #62f;
color: white;
border-radius: 50% / 20px;
padding: 30px;
width: 1em;
height: 1.75em;
content: "";
display: block;
position: absolute;
top: 2px;
left: 8px;
}
.box::before {
background: #62f;
color: white;
border-radius: 20px / 50%;
padding: 30px;
width: 1.7em;
height: 1em;
content: "";
display: block;
position: absolute;
top: 8px;
left: 2px;
}
.box > span {
position: absolute;
top: 32px;
left: 36px;
z-index: 5;
color: white;
font-size: 1.5em;
font-family: sans-serif;
}
<div class="box"><span>8</span></div>
推荐阅读
- python - 如何使用 cv2.KMEANS_USE_INITIAL_LABELS 在 opencv python 中设置初始中心
- maven - 如何在 Maven 构建模板中使用 VSTS 调用特定于环境的 app.properties
- javascript - Edit D3 SVG's links position in a "radial" Chart
- r - R:更改单元格中的值,如果其上方和下方的值相互匹配,则不使用 for 循环
- python - 以不同的顺序对多列上的结构化 Numpy 数组进行排序
- sas - SAS中最大统计量的动态计算
- activemq-artemis - ActiveMQ Artemis 在启动时阻塞
- sql - 如何选择可能有前导零的非整数(varchars)?
- python - 获取调用 python 脚本的 bash 脚本的位置
- ms-access - 查询未在用户输入 MS Access 上返回行