简体   繁体   English

在svg中更改半圈的背景颜色

[英]change background color of half circle in svg

i want to create First and third quarter moon on this svg code 我想在此svg代码上创建第一季度和第三季度的月亮

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680.336 380.336">
    <g stroke="#000">
      <circle cx="30" cy="30" r="27" style="fill:#FFF;stroke-width:4"/>  
 </g>
</svg>

like this 像这样

First quarter moon 第一季度月亮

在此处输入图片说明

Third quarter moon 第三季度月亮

在此处输入图片说明

here moon border is light but i want to like strong 这里的月亮边界很轻,但我想喜欢结实的

There are a number of ways you could do it. 您可以通过多种方式进行操作。 Other than making a half-circle in a vector editor of course. 当然除了在矢量编辑器中制作半圆。

The simplest may be to use a clipPath. 最简单的方法可能是使用clipPath。 We take a copy of the circle, but filled with black. 我们取一个圆圈的副本,但用黑色填充。 Then we cut off half of it. 然后我们剪掉一半。

 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680.336 380.336"> <defs> <clipPath id="left-half"> <rect x="0" y="0" width="30" height="60"/> </clipPath> <clipPath id="right-half"> <rect x="30" y="0" width="30" height="60"/> </clipPath> </defs> <g stroke="#000"> <circle cx="30" cy="30" r="27" style="fill:#FFF;stroke-width:4"/> <circle cx="30" cy="30" r="27" style="fill:#000;" clip-path="url(#left-half)"/> </g> </svg> 

Create a linear gradient with the fill you want. 使用所需的填充创建线性渐变。 The gradient stops provide the colour change. 渐变色标提供了颜色变化。 Having 2 stops together makes the opacity change immediate. 共有2个停靠点会使不透明度立即变化。

 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680.336 380.336"> <defs> <linearGradient id="right-half" stop-color="black"> <stop offset="0" stop-opacity="0"/> <stop offset="0.5" stop-opacity="0"/> <stop offset="0.5" stop-opacity="1"/> <stop offset="1" stop-opacity="1"/> </linearGradient> <linearGradient id="left-half" stop-color="black"> <stop offset="0" stop-opacity="1"/> <stop offset="0.5" stop-opacity="1"/> <stop offset="0.5" stop-opacity="0"/> <stop offset="1" stop-opacity="0"/> </linearGradient> </defs> <g stroke="#000"> <circle cx="30" cy="30" r="27" style="fill:url(#right-half)"/> <circle cx="90" cy="30" r="27" style="fill:url(#left-half)"/> </g> </svg> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM