由于某种原因,在CSS中设置color: #ffffff
无法应用于我的SVG。
使用以下代码的外观
我希望它看起来像这样
有趣的是,如果在SVG本身中使用#ffffff替换currentColor
,它会生效,但在CSS中进行设置不会生效。我还尝试在HTML中内联设置(style="color:#ffffff"
),以及设置stroke:#ffffff
,但都没有生效。
我已经无计可施了,如果有人知道如何解决此问题,并知道为什么在CSS中进行设置不起作用,请告诉我。
以下是我的代码:
download.svg:
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="feather feather-download"
>
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
<polyline points="7 10 12 15 17 10"></polyline>
<line x1="12" y1="15" x2="12" y2="3"></line>
</svg>
我的图片:
<button type='button' class='btn btn-primary' on:click={ExportXlsx}>
Last ned
<img class='test' alt='download' src='/images/download.svg' />
</button>
我的 CSS:
.test{
color: #ffffff !important;
}
<use>
元素可以解决问题:您还可以引用外部SVG资源(类似于img)。另请参见如何访问外部插入的SVG文件的样式属性? - herrstrietzel