【发布时间】:2014-10-05 02:12:59
【问题描述】:
我想创建一个背景颜色为红色且形状完全为圆形的 div
我该怎么做?
css或jquery都可以用
【问题讨论】:
标签: css css-shapes
我想创建一个背景颜色为红色且形状完全为圆形的 div
我该怎么做?
css或jquery都可以用
【问题讨论】:
标签: css css-shapes
使用 50% 的边框半径属性。
例如:
.example-div {
border-radius: 50%
}
【讨论】:
【讨论】:
HTML div 元素与 SVG circle 基元不同,总是矩形的。
您可以使用圆角(即 CSS border-radius)使其看起来是圆的。在方形元素上,50% 的值自然形成一个圆圈。在你的 HTML 中使用这个,甚至是 SVG:
document.body.innerHTML+='<i></i>'.repeat(4);
i{border-radius:50%;display:inline-block;background:#F48024;}
svg {fill:#F48024;width:60px;height:60px;}
i:nth-of-type(1n){width:30px;height:30px;}
i:nth-of-type(2n){width:60px;height:60px;}
<svg viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
<circle cx="60" cy="60" r="60"/>
</svg>
【讨论】:
.circle {
border-radius: 50%;
width: 500px;
height: 500px;
background: red;
}
<div class="circle"></div>
看到这个FIDDLE
【讨论】:
通过使用 50% 的边框半径,您可以制作一个圆。 这是一个例子:
CSS:
#exampleCircle{
width: 500px;
height: 500px;
background: red;
border-radius: 50%;
}
HTML:
<div id = "exampleCircle"></div>
【讨论】: