我想知道是否有一个更简单的方法来创建循环div比我现在做的。
目前,我只是为每个不同的大小制作一个图像,但这样做很烦人。
有没有CSS可以让div变成圆形,我可以指定半径?
我想知道是否有一个更简单的方法来创建循环div比我现在做的。
目前,我只是为每个不同的大小制作一个图像,但这样做很烦人。
有没有CSS可以让div变成圆形,我可以指定半径?
当前回答
假设你有这样的图像:
要做出一个圆,你只需要加
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
}
如果你有一个div,你可以做同样的事情。
请看下面的例子:
.circle { 这个特性:50%; 宽度:100 px; 身高:100 px; 动画:堆叠溢出的例子无限20秒线性; pointer-events:没有; } @keyframes stackoverflow { 从{ 变换:旋转(0度); } , { 变换:旋转(360度); } } < div > <img class="circle" src="https://www.sitepoint.com/wp-content/themes/sitepoint/assets/images/icon.javascript.png"> < / div >
其他回答
宽度和高度取决于大小,但要保持两者相等 .circle { 背景颜色:灰色; 身高:400 px; 宽度:400 px; 这个特性:100%; } < div class = "圆" > < / div >
对于circle,创建一个div元素,然后输入width = 2倍的边框半径= 2倍的填充。同样line-height = 0 例如,用50px作为圆的半径,下面的代码工作得很好:
width: 100px;
padding: 50px 0;
border: solid;
line-height: 0px;
border-radius: 50px;
.circle { 高度:20眼动; 宽度:20眼动; 这个特性:50%; background - color: # EF6A6A; } < div class = "圆" > < / div >
将元素每边的边框半径设置为50%将创建任意大小的圆形显示:
.circle {
border-radius: 50%;
width: 200px;
height: 200px;
/* width and height can be anything, as long as they're equal */
}
你可以试试径向渐变CSS函数:
.circle {
width: 500px;
height: 500px;
border-radius: 50%;
background: #ffffff; /* Old browsers */
background: -moz-radial-gradient(center, ellipse cover, #ffffff 17%, #ff0a0a 19%, #ff2828 40%, #000000 41%); /* FF3.6-15 */
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 17%,#ff0a0a 19%,#ff2828 40%,#000000 41%); /* Chrome10-25,Safari5.1-6 */
background: radial-gradient(ellipse at center, #ffffff 17%,#ff0a0a 19%,#ff2828 40%,#000000 41%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
}
应用到一个div图层:
<div class="circle"></div>