簡體   English   中英

SVG currentColor 在 GitHub 自述文件中不起作用?

[英]SVG currentColor not working in GitHub README?

我正在嘗試使 SVG 顏色與 GitHub 自述文件中周圍文本的顏色相匹配。 (如果將文本設置為"fill=black" ,它將在 GitHub 的暗模式下幾乎不可見。)

這里,我收集到我可以使用

fill="currentColor"

獲取最近(周圍)CSS 元素的color屬性。 我用顯示一個簡單圓圈的 SVG 進行了嘗試:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" viewBox="-500 -500 1000 1000">
  <circle r="400" fill="currentColor" />
</svg>

SVG 嵌入在自述文件中

<p align="center">
  <img src="https://nschloe.github.io/smoothfit/disk.svg" width="60%">
</p>

但是,填充顏色將始終顯示為黑色。

在此處輸入圖像描述

(從這里)。

知道出了什么問題嗎?

@Alicia 的重播是正確的解釋:要使currentColor起作用,SVG 需要嵌入到 HTML 中。 如果它作為img標簽包含,則它不起作用。 這個

<!DOCTYPE html>
<html>
<body>
  Lorem ipsum
  <p style="color:red">
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <circle r="100" fill="currentColor" />
  </svg>
  </p>

  dolor sit amet
  <p style="color:red">
    <img src="https://nschloe.github.io/smoothfit/disk.svg" width="100px"/>
  </p>
</body>
</html>

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM