gpt4 book ai didi

html - 创建 CSS 半圆

转载 作者:太空狗 更新时间:2023-10-29 13:37:04 28 4
gpt4 key购买 nike

我有一个包含如下数字的实心圆圈:

enter image description here

我如何将它分成两个半圆,以便我可以在其中存储两个不同的数字,如下所示:

enter image description here

我的 CSS 如下:

.oval {
display: inline-block;
width: 75px;
height: 75px;
border-radius: 50%;
background: #000000;
color: white;
line-height: 75px;
font-size: medium;
}

最佳答案

你可以使用border-radius

.left-half,
.right-half {
float: left;
width: 40px;
height: 80px;
line-height: 80px;
color: white;
text-align: center;
margin: 0 1px;
background: black;
}
.left-half:nth-child(1) {
border-radius: 80px 0 0 80px;
}
.right-half:nth-child(2) {
border-radius: 0 80px 80px 0;
}
<div class="circle">
<div class="left-half">21</div>
<div class="right-half">12</div>
</div>

或者你可以使用SVG

.text {
font-size: 16px;
fill: white;
}
<svg width="105.5px" height="97.874px" viewBox="0 0 105.5 97.874">
<path d="M50.423,0.609v96.76c-26.72,0-48.38-21.66-48.38-48.38C2.043,22.269,23.703,0.609,50.423,0.609z" />
<path d="M103.526,49.494c0,26.72-21.66,48.38-48.38,48.38V1.114C81.866,1.114,103.526,22.774,103.526,49.494z" />
<text transform="matrix(1 0 0 1 20.0771 52.5107)" class="text">21</text>
<text transform="matrix(1 0 0 1 73.1807 53.0166)" class="text">12</text>
</svg>


更新:您也可以只创建内部有两个 span 的圆,并在中间添加一条线 pseudo-class

.circle {
width: 70px;
height: 70px;
background: black;
border-radius: 50%;
display: flex;
align-items: center;
color: white;
position: relative;
}
span {
flex: 1;
text-align: center;
}
.circle:before {
content: "";
width: 2px;
position: absolute;
height: 100%;
background: white;
top: 0;
left: 50%;
transform: translateX(-50%);
}
<div class="circle">
<span>12</span><span>24</span>
</div>

关于html - 创建 CSS 半圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36891361/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com