gpt4 book ai didi

css - CSS 中的内联 SVG

转载 作者:IT老高 更新时间:2023-10-28 11:03:24 25 4
gpt4 key购买 nike

是否可以在 CSS 中使用内联 SVG 定义?

我的意思是这样的:

.my-class {
background-image: <svg>...</svg>;
}

最佳答案

是的,这是可能的。试试这个:

body { background-image: 
url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><linearGradient id='gradient'><stop offset='10%' stop-color='%23F00'/><stop offset='90%' stop-color='%23fcc'/> </linearGradient><rect fill='url(%23gradient)' x='0' y='0' width='100%' height='100%'/></svg>");
}

(请注意,SVG 内容需要进行 url 转义才能正常工作,例如 # 被替换为 %23。)

This works in IE 9 (which supports SVG) . Data-URL 也适用于旧版本的 IE(有限制),但它们本身不支持 SVG。

关于css - CSS 中的内联 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10768451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com