【发布时间】:2014-05-16 12:26:21
【问题描述】:
我想知道是否有人知道,是否可以仅使用 CSS 创建这样的渐变?我知道它可以使用画布来完成,但没有可能吗?
【问题讨论】:
-
立刻让我想起了this post...
我想知道是否有人知道,是否可以仅使用 CSS 创建这样的渐变?我知道它可以使用画布来完成,但没有可能吗?
【问题讨论】:
这几乎是我在不熬夜摆弄它的情况下尽可能接近的结果,但是是的,这是可能的! [不过,只有诡计,对不起;我不知道有什么方法可以创建这样一个合法的 CSS3 渐变环,但至少,这是纯 HTML/CSS!]
[我为它的混乱道歉]
.tophalf {
position:absolute;
width: 250px; height:125px;
-webkit-border-top-left-radius: 193px;
-webkit-border-top-right-radius: 193px;
-moz-border-radius-topleft: 193px;
-moz-border-radius-topright: 193px;
border-top-left-radius: 193px;
border-top-right-radius: 193px;
background: -moz-linear-gradient(left, #db9771 1%, #cc5f7f 51%, #c30380 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(1%,#db9771), color-stop(51%,#cc5f7f), color-stop(100%,#c30380));
background: -webkit-linear-gradient(left, #db9771 1%,#cc5f7f 51%,#c30380 100%);
background: -o-linear-gradient(left, #db9771 1%,#cc5f7f 51%,#c30380 100%);
background: -ms-linear-gradient(left, #db9771 1%,#cc5f7f 51%,#c30380 100%);
background: linear-gradient(to right, #db9771 1%,#cc5f7f 51%,#c30380 100%);
}
.inner {
position: relative; z-index: 1;
top: 20px; left: 20px;
width: 210px; height: 210px;
background-color: white;
border-radius: 100%;
}
.bottomhalf {
position:absolute;
top:133px;
width: 250px; height:125px;
-webkit-border-bottom-right-radius: 193px;
-webkit-border-bottom-left-radius: 193px;
-moz-border-radius-bottomright: 193px;
-moz-border-radius-bottomleft: 193px;
border-bottom-right-radius: 193px;
border-bottom-left-radius: 193px;
background: -moz-linear-gradient(left, #db9771 1%, #edc552 51%, #ffec00 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(1%,#db9771), color-stop(51%,#edc552), color-stop(100%,#ffec00));
background: -webkit-linear-gradient(left, #db9771 1%,#edc552 51%,#ffec00 100%);
background: -o-linear-gradient(left, #db9771 1%,#edc552 51%,#ffec00 100%);
background: -ms-linear-gradient(left, #db9771 1%,#edc552 51%,#ffec00 100%);
background: linear-gradient(to right, #db9771 1%,#edc552 51%,#ffec00 100%);
}
<div class='container'>
<div class='tophalf'></div>
<div class='inner'></div>
<div class='bottomhalf'></div>
</div>
为了简短起见,我将两个半圆放在一起,给每一半一个不同的渐变,但保持左侧的起始颜色相同,确保“接缝”只会在一侧。
然后,我在两个半圆的中间放了一个白色的整圆,把中间的所有东西都隐藏起来,成功地创建了一个渐变环。
编辑:糟糕!没有Gradient Editor,我无法做到。
【讨论】:
只是为了……
修复过渡部分...
#rb::before {
width: 100%;
height: 20%;
margin-top: -10%;
background-color: #cddc39;
}
#rb::after {
width: 20%;
height: 20%;
margin-left: -10%;
margin-top: 70%;
background-color: #ffeb3b;
}
这里有详细信息:jsFiddle (https://jsfiddle.net/7kfuzwyc/3/)
【讨论】: