SVG小记——SVG Sprites
来源:互联网 发布:ubuntu安装chrome 编辑:程序博客网 时间:2024/05/01 18:46
<!doctype html><html lang="en"> <head> <meta charset="utf-8" /> <title>David Darnes - Web Designer & Front-end Developer</title> <style> .icon { max-width: 40px; max-height: 40px;} </style> <svg display="none" version="1.1" xmlns="http://www.w3.org/2000/svg"> <symbol id="icon1" fill="#55ACEE"> <title>icon1</title> <desc>icon1</desc> <path d="..." id="bird"></path> </symbol> <symbol id="icon2"> <title>icon2</title> <desc>icon2</desc> <path d="..." id="ball" fill="#EA4C89"></path> <path d="..." id="ball-lines" fill="#C32361"></path> </symbol> <symbol id="icon3" fill="#161614"> <title>icon3</title> <desc>icon3</desc> <path d="..." id="octocat"></path> </symbol> </svg> </head> <body> <div class="section"> <a href="#"> <svg class="icon" viewBox="0 0 50 41"> <switch> <use xlink:href="#icon1"></use> <foreignObject> <img class="icon" src="img/icon1.png" alt="Twitter"> </foreignObject> </switch> </svg> </a> <a href="#"> <svg class="icon" viewBox="0 0 50 50"> <switch> <use xlink:href="#icon2"></use> <foreignObject> <img class="icon" src="img/icon2.png" alt="Dribbble"> </foreignObject> </switch> </svg> </a> <a href="#"> <svg class="icon" viewBox="0 0 50 50"> <switch> <use xlink:href="#icon3"></use> <foreignObject> <img class="icon" src="img/icon3.png" alt="GitHub"> </foreignObject> </switch> </svg> </a> </div></body>
使用<symbol>
元素不仅仅更加地语义化,至少在我的例子中,我们还可以避免<svg>
元素上的viewbox属性的重复出现。
另外我们现在还可以把之前移除的title和desc元素放回来,用他们来提高我们图标的可访问性。
0 0
- SVG小记——SVG Sprites
- SVG小记——入门,clipPath
- SVG小记——viewport,viewBox,preserveAspectRatio
- SVG小记——transform属性,建立新视窗
- svg
- SVG
- SVG
- SVG
- SVG
- SVG
- svg
- svg
- SVG
- SVG
- SVG
- SVG
- SVG
- svg
- 闲谈编程之 内存
- CentOS 6.6源码编译升级GCC至4.8.2
- web服务器之LNMP(1)Ubuntu中Nginx的安装与配置
- Extjs4中up()和down()的用法
- @dynamic关键字
- SVG小记——SVG Sprites
- JSP:九大内置对象
- 【Linux】test命令
- Google Protocol Buffers介绍和总结
- Java 类加载与初始化
- 闲谈编程之 Java内部类
- error in invoking target install of makefile
- DirectFB接口资料
- Linux初学——目录与路径