作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我在这里使用 SVG 我尝试像这样将渐变添加到 SVG
白色和灰色渐变,但我无法获得所需的输出。谁能指出我正确的方向。
<svg viewBox="0 0 400 400">
<defs>
<linearGradient id="GradientRepeat" x1="0" y1="1" x2="0" y2="0" spreadMethod="repeat">
<stop offset="0.05" stop-color="#fff" stop-opacity="0"/>
<stop offset="1" stop-color="#777" stop-opacity="1"/>
</linearGradient>
</defs>
<circle class="sub-menu-circle" cx="0" cy="200" r="160" fill="url(#GradientRepeat)" />
</svg>
<svg viewBox="0 0 700 700" class="bubble-svg">
<defs>
<linearGradient id="GradientRepeat" x1="0" y1="1" x2="0" y2="0" spreadMethod="repeat" gradientTransform="rotate(170)">
<stop offset="0%" stop-color="#fff" stop-opacity="0"/>
<stop offset="10%" stop-color="#bdbdbd" stop-opacity="0.5"/>
<stop offset="20%" stop-color="#fff" stop-opacity="0"/>
<stop offset="30%" stop-color="#bdbdbd" stop-opacity="0.5"/>
<stop offset="40%" stop-color="#fff" stop-opacity="0"/>
<stop offset="50%" stop-color="#bdbdbd" stop-opacity="1"/>
<stop offset="60%" stop-color="#fff" stop-opacity="0"/>
<stop offset="70%" stop-color="#bdbdbd" stop-opacity="0.5"/>
<stop offset="80%" stop-color="#bdbdbd" stop-opacity="0"/>
<stop offset="100%" stop-color="#fbfbfb" stop-opacity="0.5"/>
</linearGradient>
</defs>
<circle class="sub-menu-circle" cx="0" cy="200" r="160" fill="url(#GradientRepeat)" />
</svg>
最佳答案
微调灰色和白色阴影的渲染取决于您使用的视频卡、浏览器和操作系统。
因此,我发送了几个选项。您可以使用您喜欢的任何选项或通过更改颜色为自己稍微调整。
<svg viewBox="0 0 700 700" class="bubble-svg">
<defs>
<linearGradient id="GradientRepeat" x1="0" y1="0" x2="0" y2="1" spreadMethod="repeat" gradientTransform="rotate(170)">
<stop offset="0%" stop-color="#B4B4B5" stop-opacity="1"/>
<stop offset="17%" stop-color="#fff" stop-opacity="0.8"/>
<stop offset="30%" stop-color="#B4B4B5" stop-opacity="0.6"/>
<stop offset="49%" stop-color="#fff" stop-opacity="0.8"/>
<stop offset="61%" stop-color="#B4B4B5" stop-opacity="0.6"/>
<stop offset="80%" stop-color="#fff" stop-opacity="0.8"/>
<stop offset="95%" stop-color="#B4B4B5" stop-opacity="1"/>
</linearGradient>
</defs>
<circle class="sub-menu-circle" cx="0" cy="200" r="160" fill="url(#GradientRepeat)" />
</svg>
2#变体
<svg viewBox="0 0 700 700" class="bubble-svg">
<defs>
<linearGradient id="GradientRepeat" x1="0" y1="0" x2="0" y2="1" spreadMethod="repeat" gradientTransform="rotate(170)">
<stop offset="0%" stop-color="#B4B4B5" stop-opacity="1"/>
<stop offset="17%" stop-color="#F6F6F6" stop-opacity="0.8"/>
<stop offset="30%" stop-color="#B4B4B5" stop-opacity="0.6"/>
<stop offset="49%" stop-color="#F6F6F6" stop-opacity="0.8"/>
<stop offset="61%" stop-color="#B4B4B5" stop-opacity="0.6"/>
<stop offset="80%" stop-color="#F6F6F6" stop-opacity="0.8"/>
<stop offset="95%" stop-color="#B4B4B5" stop-opacity="1"/>
</linearGradient>
</defs>
<circle class="sub-menu-circle" cx="0" cy="200" r="160" fill="url(#GradientRepeat)" />
</svg>
3#变体
<svg viewBox="0 0 700 700" class="bubble-svg">
<defs>
<linearGradient id="GradientRepeat" x1="0" y1="0" x2="0" y2="1" spreadMethod="repeat" gradientTransform="rotate(170)">
<stop offset="0%" stop-color="#ABABAC" stop-opacity="1"/>
<stop offset="17%" stop-color="#fff" stop-opacity="0.8"/>
<stop offset="30%" stop-color="#ABABAC" stop-opacity="0.6"/>
<stop offset="49%" stop-color="#fff" stop-opacity="0.8"/>
<stop offset="61%" stop-color="#ABABAC" stop-opacity="0.6"/>
<stop offset="80%" stop-color="#fff" stop-opacity="0.8"/>
<stop offset="95%" stop-color="#ABABAC" stop-opacity="1"/>
</linearGradient>
</defs>
<circle class="sub-menu-circle" cx="0" cy="200" r="160" fill="url(#GradientRepeat)" />
</svg>
为了更精确地调整您的品味,最好使用 stop-color
和 stop-opacity
选择值。
更新
要使方法 spreadMethod ="repeat"
在您的示例中开始工作,您需要将梯度覆盖范围减少三倍。为此,设置 x1 ="0"y1 ="0"x2 ="0"y2 ="0.33"
结果,调整一个波的色调,我们得到它的完全相同的副本,与大量 stop-offset
<svg viewBox="0 0 700 700" class="bubble-svg">
<defs>
<linearGradient id="GradientRepeat" x1="0" y1="0" x2="0" y2="0.33"
spreadMethod="repeat" gradientTransform="rotate(170)">
<stop offset="10%" stop-color="#ABABAC" stop-opacity="1"/>
<stop offset="50%" stop-color="#ffffff" stop-opacity="0.8"/>
<stop offset="85%" stop-color="#ABABAC" stop-opacity="1"/>
</linearGradient>
</defs>
<circle class="sub-menu-circle" cx="0" cy="200" r="160" fill="url(#GradientRepeat)" />
</svg>
关于javascript - SVG渐变色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59676000/
我是一名优秀的程序员,十分优秀!