在CSS中内联SVG [英] Inline SVG in CSS

查看:212
本文介绍了在CSS中内联SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to use an inline SVG definition in CSS?

我的意思是:

.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>");
      }




  • http://jsfiddle.net/6WAtQ/

    • http://jsfiddle.net/6WAtQ/
    • (请注意,SVG内容需要进行网址转义才能正常工作,例如被替换为%23 。)

      (Note that the SVG content needs to be url-escaped for this to work, e.g. # gets replaced with %23.)

      这适用于IE 9(支持SVG)。数据URL也在旧版本的IE中工作(有限制),但它们本身不支持SVG。

      This works in IE 9 (which supports SVG). Data-URLs work in older versions of IE too (with limitations), but they don’t natively support SVG.

      这篇关于在CSS中内联SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆