javascript - <使用> - SVG : Stroke of Circle overriding stroke of use element

标签 javascript html css svg

两者的行程<use>元素在这里被忽略。 <circle>的笔触颜色设置为蓝色,同时出现在 <use> 上元素也。为什么?

我想要所有 3 个元素的不同条纹颜色。但它不起作用。

<svg width="300" class="svg-elem" viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg">  
  <circle id="myCircle" cx="5" cy="5" r="4" stroke="blue"/>
   
  <use class="circle1" href="#myCircle" x="10" stroke="grey" fill="blue"/>
   
  <use href="#myCircle" x="20" fill="white" stroke="red"/>
</svg>

最佳答案

因为 circle仍然覆盖 <use> .

enter image description here

您可以考虑使用 CSS 变量来控制笔触颜色,如下所示。

<svg width="300" class="svg-elem" viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg">  
  <circle id="myCircle" cx="5" cy="5" r="4" style="stroke:var(--stroke, blue)"/>
   
  <use class="circle1" href="#myCircle" x="10" style="--stroke:gray;" fill="blue"/>
   
  <use href="#myCircle" x="20" fill="white" style="--stroke:red;"/>
</svg>

关于javascript - <使用> - SVG : Stroke of Circle overriding stroke of use element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63467183/

相关文章:

javascript - 通过按键和点击执行 JavaScript 代码的不同部分

javascript - 如何访问 svg 内部 id 并让 CSS 更改该 id 的填充颜色?

css - 悬停 jquery - 影响 DIV 类的 NAVbar CSS

javascript - 为什么我的 div 在使用 JavaScript 更改其类时没有更新?

javascript - 使用 knockout 将数组中某些输入的值与跨度绑定(bind)

javascript - Cheerio - 查找并打印与查询匹配的所有属性

javascript - 如何访问 .file 数组?

javascript - 访问父级最近的子级

javascript - 无法计算出 jQuery find 来定位层次结构中的对象

css - 我的网站标题图片未在移动设备上调整大小