【发布时间】:2011-10-19 16:49:25
【问题描述】:
是否可以仅使用可在大多数浏览器(IE、Mozilla、Safari)上使用的 css 绘制圆圈?
【问题讨论】:
标签: html css css-shapes
是否可以仅使用可在大多数浏览器(IE、Mozilla、Safari)上使用的 css 绘制圆圈?
【问题讨论】:
标签: html css css-shapes
是的,画一个盒子并给它一个边框半径,它是盒子宽度的一半:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
工作演示:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
<div id="circle"></div>
【讨论】:
您可以将 .before 与带有 unicode 符号的内容一起用于圆 (25CF)。
.circle:before {
content: ' \25CF';
font-size: 200px;
}
<span class="circle"></span>
我建议这样做,因为边界半径在 IE8 及以下版本中不起作用(我承认这个建议有点精神)。
【讨论】:
:before 在 IE7 及以下版本中不起作用,因此该方法仅获得对 IE8 的支持,但很难正确定位圆圈。例如,200 像素的字体大小不等于直径为 200 像素的圆,并且在某些系统上您会失去抗锯齿功能。
margin: -0.5em -0.3em -0.3em -0.1em
border-radius,这将使其呈圆形。 (注意:long time 不需要前缀)
background-color/gradients/(甚至pseudo elements)来创建类似这样的东西:.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
}
.sphere {
height: 200px;
width: 200px;
border-radius: 50%;
text-align: center;
vertical-align: middle;
font-size: 500%;
position: relative;
box-shadow: inset -10px -10px 100px #000, 10px 10px 20px black, inset 0px 0px 10px black;
display: inline-block;
margin: 5%;
}
.sphere::after {
background-color: rgba(255, 255, 255, 0.3);
content: '';
height: 45%;
width: 12%;
position: absolute;
top: 4%;
left: 15%;
border-radius: 50%;
transform: rotate(40deg);
}
<div class="sphere red"></div>
<div class="sphere green"></div>
<div class="sphere blue"></div>
<div class="sphere yellow"></div>
<div class="sphere"></div>
【讨论】:
边框半径是一个不错的选择,如果在使用旧 IE 版本时遇到困难,请尝试 HTML 代码
•
并使用 css 更改颜色。输出:
•
【讨论】:
这适用于所有浏览器
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}
【讨论】:
是的..这是我的代码:
<style>
.circle{
width: 100px;
height: 100px;
border-radius: 50%;
background-color: blue
}
</style>
<div class="circle">
</div>
【讨论】: