【发布时间】:2022-01-21 21:16:06
【问题描述】:
由于某种原因,在 CSS 中设置 color: #ffffff 不适用于我的 SVG。
下面的代码看起来如何
我希望它看起来如何
有趣的是,如果我在 SVG 本身中将 currentColor 替换为 #ffffff,它会起作用,但在我的 CSS 中设置它不会做任何事情。我还尝试在 HTML (style="color:#ffffff") 中将其设置为内联,并设置stroke: #ffffff,但这也没有任何作用。
我没有想法,所以如果有人知道如何做到这一点,以及为什么在 css 中设置它不起作用,请告诉我。
这是我的代码:
下载.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)。另见How to access style properties of externally insert svg file?
标签: html css svg svelte bootstrap-5