Svg 如何将渐变应用于标记?
在SVG中,如何将应用于直线的渐变应用于其标记端Svg 如何将渐变应用于标记?,svg,gradient,marker,Svg,Gradient,Marker,在SVG中,如何将应用于直线的渐变应用于其标记端 <?xml version='1.0' encoding='UTF-8' standalone="yes"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="820px" height="500px" viewBox="0 0 820 500" v
<?xml version='1.0' encoding='UTF-8' standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="820px"
height="500px"
viewBox="0 0 820 500"
version="1.1" >
<style>
.axis3 {
stroke-width: 40px;
marker-end:url(#arrow);
stroke: url('#gradient_3');
fill: url('#gradient_3');
height: 30px;
}
.axis4 {
stroke-width: 40px;
marker-end:url(#arrow);
stroke: url('#gradient_4');
fill: url('#gradient_4'); /* corrected */
height: 30px;
}
</style>
<defs>
<marker
id="arrow"
markerWidth="20"
markerHeight="40"
refX="0"
refY="20"
orient="auto"
markerUnits="userSpaceOnUse"
style="fill:inherit;">
<path style="stroke:none;fill:inherit;overflow:visible;" d="M0 0 L20 20 L0 40 Z" />
</marker>
<linearGradient id="gradient_3" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="userSpaceOnUse" >
<stop offset="0%" stop-color="yellow" />
<stop offset="20%" stop-color="red" />
</linearGradient>
<linearGradient id="gradient_4" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="userSpaceOnUse" >
<stop offset="0%" stop-color="blue" />
<stop offset="20%" stop-color="green" />
</linearGradient>
</defs>
<line class="axis3" x1="50" x2="400" y1="50" y2="50" />
<line class="axis4" x1="50" x2="400" y1="100" y2="100" />
</svg>
.3{
笔划宽度:40px;
标记结束:url(#箭头);
笔划:url(“#渐变#3”);
填充:url(“#渐变#3”);
高度:30px;
}
.axis4{
笔划宽度:40px;
标记结束:url(#箭头);
笔划:url(“#渐变#4”);
填充:url(“#渐变#4”);/*已更正*/
高度:30px;
}
对于上面的代码,标记始终为黑色
由于存在多个具有不同梯度的元素线,因此不能直接在路径上应用梯度。
我尝试添加style=“fill:inherit”-但没有成功。我将这样做: 而不是
fill:inherit
我正在为svg元素设置两个css变量:style=“--fill:url(#gradient_3);--stroke:url(#gradient_4)”
。直线和标记都使用这些变量进行填充
和笔划
或者,您可以选择直接在代码中使用渐变。回答“”提到没有从相关路径继承颜色。
自回答此问题以来,情况一直没有变化。感谢您的反馈:我已经澄清了我的需求。Vivaldi和Chrome并不是天生在标记端应用渐变的。Internet Explorer本机在标记端应用渐变-除了它是标记开始时预期的渲染。。。