[英]Add linear gradient to SVG circle
I am trying to add a gradient I got from online to my SVG circle. 我正在尝试添加从在线到我的SVG圈子的渐变。 This is my gradient 这是我的渐变
background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
I am trying to add this gradient type to my circle instead of the "fill="yellow". I tried inserting the gradient in the code but nothing. Tried searching/playing around with it but, ended up with nothing. Here is my code 我正在尝试将此渐变类型添加到我的圆圈而不是“fill =”yellow“。我尝试在代码中插入渐变但没有。尝试搜索/玩弄它但最后没有任何结果。这是我的代码
Codepen http://codepen.io/anon/pen/wdaMVR Codepen http://codepen.io/anon/pen/wdaMVR
.circlesvg{ position: absolute; left: 0; top: 0; } #firstCircle{ animation: fadeAndScale 33s ease-in infinite; -ms-animation: fadeAndScale 33s ease-in infinite; -webkit-animation: fadeAndScale 33s ease-in infinite; -moz-animation: fadeAndScale 33s ease-in infinite; -o-animation: fadeAndScale 33s ease-in infinite; transition-timing-function: linear; } @keyframes fadeAndScale{ 0%{ z-index: 100; transform: scale(0); transform: translate(200px, 200px); } 100%{ z-index: 0; transform: scale(200); } }
<svg width="100%" height="100%" class="circlesvg"> <circle id="firstCircle" cx="0" cy="0" r="40" fill="yellow"></circle> </svg>
You would have to use SVG's <linearGradient>
element and then reference it as the fill: 您必须使用SVG的<linearGradient>
元素,然后将其作为填充引用:
<defs>
<linearGradient id="gradient">
<stop offset="0%" stop-color="#a18cd1"/>
<stop offset="100%" stop-color="#fbc2eb"/>
</linearGradient>
</defs>
<circle id="firstCircle" cx="0" cy="0" r="40" fill="url(#gradient)"></circle>
http://codepen.io/anon/pen/VbLaYy http://codepen.io/anon/pen/VbLaYy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.