use 应用css样式(一)

为方便看,这里的CSS是内嵌在svg中的。

defs标签定义了一个元素,只是定义不会被解析显示。

SVG中的use标签是用来引用SVG中的可视化元素。

use标签引用的元素不会继承<use>元素本身和其父元素的属性。

这里就是用use标签引用defs定义的元素。

 

use标签用class属性引用css的某个样式。

如果被引用元素已经有class属性值,它的样式会保持原样。

 

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">

<svg a3:scriptImplementation="Adobe" viewBox="0 0 770 495"

width="770" height="495"

xmlns="http://www.w3.org/2000/svg"

xmlns:xlink="http://www.w3.org/1999/xlink"

xmlns:ev="http://www.w3.org/2001/xml-events"

xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/">

<style type="text/css">

       <![CDATA[    

       .t1{

       fill: red;

       stroke: blue;

       stroke-width: 3

       }

       .t2{

       fill: yellow;

       stroke: red;

       stroke-width: 1

       }

       .t3{

       fill: blue;

       stroke: red;

       stroke-width: 1

       }

       .g{

       fill: green;

       stroke: red;

       stroke-width: 1

       }

       ]]>

    </style>

   

<defs>

<g id="a" class="g">

<rect width="60" height="10" />

</g>

<rect  id="b" width="60" height="10" />

<rect  id="c" width="60" height="10" />

</defs>

 

<use x="100" y="100" xlink:href="#a"  class="tl" />

<use x="100" y="200" xlink:href="#b" class="t2" />

<use x="100" y="300" xlink:href="#c" class="t3" />

</svg>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值