svg - 影根?调出描边颜色
问题描述
我在 SVG 中调出笔画,如果我不对样式设置任何类,它就可以工作。但我需要把它放在那里,因为需要为最终用户修复以选择他们想要的任何颜色。
symbol#icon-arrow{
stroke: #ff6600;
} /*this is working*/
.icon-orange symbol#icon-arrow{
stroke: #99CA3D;
} /*this is not working, but this is what I need*/
<div id="icon-load" style="display:none;"></div>
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<symbol id="icon-arrow" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="square" stroke-linejoin="arcs" >
<path class="arrow" d="M12 19V6M5 12l7-7 7 7"/>
</symbol>
</svg>
<a href="#" class="icon">
<svg class="icon icon-orange"><use xlink:href="#icon-arrow"></use></svg>
</a>
解决方案
正如@enxaneta 所说,您必须为<use>
元素设置样式,并让颜色渗透到符号上。
但是您首先需要stroke
从符号中删除该属性。否则,该表示属性将覆盖您希望它继承的颜色。
.icon-orange use {
stroke: #ff6600;
}
.icon-green use {
stroke: #99CA3D;
}
<div id="icon-load" style="display:none;"></div>
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<symbol id="icon-arrow" viewBox="0 0 24 24" fill="none" stroke-width="3" stroke-linecap="square" stroke-linejoin="arcs" >
<path class="arrow" d="M12 19V6M5 12l7-7 7 7"/>
</symbol>
</svg>
<a href="#" class="icon">
<svg class="icon icon-orange"><use xlink:href="#icon-arrow"></use></svg>
</a>
<a href="#" class="icon">
<svg class="icon icon-green"><use xlink:href="#icon-arrow"></use></svg>
</a>
推荐阅读
- c++ - 如何获取泛型类成员函数的函数指针?
- symfony - Symfony3.4 独白包未写入自定义频道文件
- python - Celery:如何自定义多处理池初始化?
- java - 在 android 中转到应用程序的特定部分
- python - 从代码单元跳转到特定代码单元(即以编程方式)(jupyter / ipython)
- spring - Spring:如何在JSP中获取模型属性并检查它是否为空?
- react-native - 使用 asyncstorage 对本机更改状态做出反应
- java - 在android中更改两个模块的包名的问题
- image-processing - 我如何将 64 x 64 像素图像划分为 3 × 3 重叠区域(重叠大小为 14 像素)
- vb.net - vb.net 和 ms access 2016 登录表单