CSS 围绕整圈的半弧形
CSS half arch around full circle
我正在尝试围绕一个完整的圆创建一个半拱形,如下所示。我将如何在 css 中创建它?到目前为止,我只创建了圆圈,但不知道如何做拱门。
.circle {
width: 45px;
height: 45px;
border-radius: 50%;
font-size: 20px;
color: #fff;
line-height: 45px;
text-align: center;
position: relative;
background: #BDBDBD;
}
<div class="circle">1</div>
您可以使用:after
伪元素创建半圆。您还需要使用 bottom-right
和 top-right
border-radius.
.circle {
width: 100px;
height: 100px;
margin: 50px;
position: relative;
line-height: 100px;
text-align: center;
border-radius: 50%;
background: #BDBDBD;
color: white;
}
.circle:after {
content: '';
position: absolute;
top: 0;
right: 0;
border: 10px solid gray;
border-left: 0;
border-bottom-right-radius: 100px;
border-top-right-radius: 100px;
width: 55px;
height: calc(100% + 10px);
transform: translate(15px, -15px);
}
<div class="circle">1</div>
这是基于 jcaron 对问题的评论。我用外圈包裹圆 div 以创建 "white space between greys" 区域。
然而,Nenad Vracar 的回答似乎更加清晰。
.outer-circle {
width: 45px;
height: 45px;
border-style: solid;
border-width: 1x 1px 0 0;
border-color: #BDBDBD #BDBDBD transparent transparent;
border-radius: 50%;
font-size: 20px;
color: #fff;
line-height: 45px;
text-align: center;
position: relative;
background: #fff;
padding: 3px;
transform: rotate(45deg);
}
.circle {
background: #BDBDBD;
border-radius: 50%;
transform: rotate(-45deg);
}
<div class="outer-circle">
<div class="circle">
1
</div>
</div>
是的,使用 pseudo selector
,但您的 parent
背景需要是 white
或与伪选择器合并的任何其他颜色,即圆形和半拱形之间的中心部分,或者这样做使用 canvas.
body {
background: #fff;
}
div {
width: 100px;
height: 100px;
background: #ccc;
border-radius: 50%;
text-align: center;
position: relative;
margin-top: 30px;
color: #fff;
padding-top: 40px;
box-sizing: border-box;
}
div:after {
content: "";
position: absolute;
border-top: 70px solid transparent;
border-left: 70px solid transparent;
border-right: 70px solid #ccc;
border-bottom: 70px solid #ccc;
border-radius: 50%;
z-index: -2;
transform: rotate(-45deg);
left: -15px;
top: -20px;
}
div:before {
content: "";
position: absolute;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-right: 60px solid #fff;
border-bottom: 60px solid #fff;
border-radius: 50%;
z-index: -1;
transform: rotate(-45deg);
top: -10px;
left: -7px;
}
<div>1</div>
我正在尝试围绕一个完整的圆创建一个半拱形,如下所示。我将如何在 css 中创建它?到目前为止,我只创建了圆圈,但不知道如何做拱门。
.circle {
width: 45px;
height: 45px;
border-radius: 50%;
font-size: 20px;
color: #fff;
line-height: 45px;
text-align: center;
position: relative;
background: #BDBDBD;
}
<div class="circle">1</div>
您可以使用:after
伪元素创建半圆。您还需要使用 bottom-right
和 top-right
border-radius.
.circle {
width: 100px;
height: 100px;
margin: 50px;
position: relative;
line-height: 100px;
text-align: center;
border-radius: 50%;
background: #BDBDBD;
color: white;
}
.circle:after {
content: '';
position: absolute;
top: 0;
right: 0;
border: 10px solid gray;
border-left: 0;
border-bottom-right-radius: 100px;
border-top-right-radius: 100px;
width: 55px;
height: calc(100% + 10px);
transform: translate(15px, -15px);
}
<div class="circle">1</div>
这是基于 jcaron 对问题的评论。我用外圈包裹圆 div 以创建 "white space between greys" 区域。
然而,Nenad Vracar 的回答似乎更加清晰。
.outer-circle {
width: 45px;
height: 45px;
border-style: solid;
border-width: 1x 1px 0 0;
border-color: #BDBDBD #BDBDBD transparent transparent;
border-radius: 50%;
font-size: 20px;
color: #fff;
line-height: 45px;
text-align: center;
position: relative;
background: #fff;
padding: 3px;
transform: rotate(45deg);
}
.circle {
background: #BDBDBD;
border-radius: 50%;
transform: rotate(-45deg);
}
<div class="outer-circle">
<div class="circle">
1
</div>
</div>
是的,使用 pseudo selector
,但您的 parent
背景需要是 white
或与伪选择器合并的任何其他颜色,即圆形和半拱形之间的中心部分,或者这样做使用 canvas.
body {
background: #fff;
}
div {
width: 100px;
height: 100px;
background: #ccc;
border-radius: 50%;
text-align: center;
position: relative;
margin-top: 30px;
color: #fff;
padding-top: 40px;
box-sizing: border-box;
}
div:after {
content: "";
position: absolute;
border-top: 70px solid transparent;
border-left: 70px solid transparent;
border-right: 70px solid #ccc;
border-bottom: 70px solid #ccc;
border-radius: 50%;
z-index: -2;
transform: rotate(-45deg);
left: -15px;
top: -20px;
}
div:before {
content: "";
position: absolute;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-right: 60px solid #fff;
border-bottom: 60px solid #fff;
border-radius: 50%;
z-index: -1;
transform: rotate(-45deg);
top: -10px;
left: -7px;
}
<div>1</div>