如何使用HTML5和CSS3绘制圆?
是否也可以将文本放入其中?
发布于 2014-12-21 14:51:09
有几个unicode圆圈可以使用:
* { font-size: 50px; }
○
◌
◍
◎
●
更多形状here。
如果需要,可以在圆圈上叠加文本:
#container {
position: relative;
}
#circle {
font-size: 50px;
color: #58f;
}
#text {
z-index: 1;
position: absolute;
top: 21px;
left: 11px;
}
<div id="container">
<div id="circle">●</div>
<div id="text">a</div>
</div>
您也可以使用自定义字体(如this one),因为并非所有的计算机/浏览器都安装了相同的字体,因此您希望在不同的系统上使用相同的字体。
发布于 2015-07-30 02:13:54
到了2015年,你只需要15行CSS (Fiddle)就可以让文本居中显示:
body {
background-color: #fff;
}
#circle {
position: relative;
background-color: #09f;
margin: 20px auto;
width: 400px;
height: 400px;
border-radius: 200px;
}
#text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>circle with text</title>
</head>
<body>
<div id="circle">
<div id="text">Text in the circle</div>
</div>
</body>
</html>
如果没有任何-webkit-
s,它可以在IE11、火狐、Chrome和Opera上运行,并且它是有效的HTML5 (实验性)和CSS3。
MS Edge (2020)也是如此。
发布于 2017-04-27 11:50:07
.circle{
height: 65px;
width: 65px;
border-radius: 50%;
border:1px solid red;
line-height: 65px;
text-align: center;
}
<div class="circle"><span>text</span></div>
https://stackoverflow.com/questions/6921792
复制相似问题