一個img包含 svg 的div
<div class="expand-button" onclick="toggleExpand()">
<img src="Resources/iconmonstr-arrow-65.svg" alt="arrow">
</div>
我試過使用 svg 作為背景background: url('Resources/iconmonstr-arrow-65.svg')并使用fill: white;
也試過了,fill: white !important;
但似乎不起作用。
我錯過了什么?
uj5u.com熱心網友回復:
如果您打開.svg檔案,請嘗試向其中添加fill屬性。舉個例子:<svg fill="white"
據我了解,您正在嘗試使用 SVG 屬性設定影像,例如fill,但是這必須直接對 SVG 本身完成。這是另一個用紅色填充的普通圓形輪廓的示例。
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 24 24" fill="red" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-circle"><circle cx="12" cy="12" r="10"></circle></svg>
出于任何其他原因,請考慮<img src="Resources/iconmonstr-arrow-65.svg" alt="如何讓填充屬性在 svg 上作業?">簡單地替換為 svg 本身——盡管它不是最理想的方法,例如:
<div class="expand-button" onclick="toggleExpand()">
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 24 24" fill="red" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-circle"><circle cx="12" cy="12" r="10"></circle></svg>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/395757.html
