littlecodeguy
littlecodeguy

曲中作樂,以曲為生

用 CSS 轉換 SVG 顏色

用 CSS value: currentColor 去改變 SVG fill property...

而家做網頁時好多時都需要做 light/dark mode,除咗轉 text 顏色 仲要轉埋 icon 顏色,唔想下下改 <img /> src,可以用 CSS value: currentColor 去改變 SVG fill property,只要喺 parent dom 比個 color: red, svg fill color 就會跟個值改變,仲可以配合 transition / animation 玩。

https://littlecodeguy.com/post/2022-07-13-css-svg-fill-color/


CC BY-NC-ND 2.0

Like my work?
Don't forget to support or like, so I know you are with me..

Loading...

Want to read more ?

Login with one click and join the most diverse creator community.