【问题标题】:CSS Gradient around a point围绕一个点的 CSS 渐变
【发布时间】:2014-05-16 12:26:21
【问题描述】:

我想知道是否有人知道,是否可以仅使用 CSS 创建这样的渐变?我知道它可以使用画布来完成,但没有可能吗?

【问题讨论】:

标签: css canvas


【解决方案1】:

这几乎是我在不熬夜摆弄它的情况下尽可能接近的结果,但是是的,这是可能的! [不过,只有诡计,对不起;我不知道有什么方法可以创建这样一个合法的 CSS3 渐变环,但至少,这是纯 HTML/CSS!]

JSFIDDLE

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%);
}

HTML

<div class='container'>
   <div class='tophalf'></div>
   <div class='inner'></div>
   <div class='bottomhalf'></div>
</div>

我是怎么做到的?

为了简短起见,我将两个半圆放在一起,给每一半一个不同的渐变,但保持左侧的起始颜色相同,确保“接缝”只会在一侧。

然后,我在两个半圆的中间放了一个白色的整圆,把中间的所有东西都隐藏起来,成功地创建了一个渐变环。

来源?

编辑:糟糕!没有Gradient Editor,我无法做到。

【讨论】:

  • 非常努力@Leaf,感谢您提供的信息丰富的帖子和简单的想法! :)
【解决方案2】:

只是为了……

修复过渡部分...

#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/)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 2018-01-19
    • 2012-11-21
    • 1970-01-01
    • 2014-12-26
    相关资源
    最近更新 更多