styling the SVG images
SVG不像canvas,SVG的所有元素都是以DOM元素存在于文档中的,我们可以像给任何普通的dom元素添加css样式一样,可以对svg的元素做styling.不过SVG元素的css样式名称和普通html元素的css样式属性名称还是有所区别的。下面给出一个完整的列表供参考
| CSS Property | Description |
|---|---|
fill |
Sets fill color of the shape. |
fill-opacity |
Sets fill opacity of the shape. |
fill-rule |
Sets fill rule of the shape. |
marker |
Sets marker used along the lines (edges) of this shape. |
marker-start |
Sets start marker used along the lines (edges) of this shape. |
marker-mid |
Sets mid marker used along the lines (edges) of this shape. |
marker-end |
Sets end marker used along the lines (edges) of this shape. |
stroke |
Sets the stroke (line) color used to draw the outline of this shape. |
stroke-dasharray |
Sets the stroke (line) dashing used to draw the outline of this shape. |
stroke-dashoffset |
Sets the stroke (line) dash offset used to draw the outline of this shape. |
stroke-linecap |
Sets the stroke (line) line cap used to draw the outline of this shape. Valid values are round, butt and square. |
stroke-miterlimit |
Sets the stroke (line) miter limit used to draw the outline of this shape. |
stroke-opacity |
Sets the stroke (line) opacity used to draw the outline of this shape. |
stroke-width |
Sets the stroke (line) width used to draw the outline of this shape. |
text-rendering |
Sets the text-rendering used to draw the outline of this shape. |
text元素拥有的css属性
| CSS Property | Description |
|---|---|
alignment-baseline |
Sets how the text is aligned to its x and y coordinates. |
baseline-shift |
Sets the baseline shift used to render text. |
dominant-baseline |
Sets the dominant baseline. |
glyph-orientation-horizontal |
Sets horizontal glyph orientation. |
glyph-orientation-vertical |
Sets vertical glyph orientation. |
kerning |
Sets the kerning of the rendered text (kern |
给SVG元素配置css样式的几种方式:
使用svg属性直接在svg元素中定义:
<circle stroke="#000000" fill="#00ff00" />
使用style属性中定义css样式的方式:
<circle style="stroke: #000000; fill:#00ff00;" />
使用inline stylesheets
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"> <style type="text/css" >
<![CDATA[ circle {
stroke: #006600;
fill: #00cc00;
} ]]>
</style> <circle cx="40" cy="40" r="24"/>
</svg>
或者
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"> <style type="text/css" >
<![CDATA[ circle.myGreen {
stroke: #006600;
fill: #00cc00;
}
circle.myRed {
stroke: #660000;
fill: #cc0000;
} ]]>
</style> <circle class="myGreen" cx="40" cy="40" r="24"/>
<circle class="myRed" cx="40" cy="100" r="24"/>
</svg>
使用外部文件方式(注意存在兼容性问题,貌似firefox 3是不工作的)
<?xml-stylesheet type="text/css" href="svg-stylesheet.css" ?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"> <circle cx="40" cy="40" r="24"
style="stroke:#006600; fill:#00cc00"/> </svg>
直接在html文档中定义和使用css样式
<html>
<body> <style>
circle {
stroke: #006600;
fill : #00cc00;
}
</style> <svg>
<circle cx="40" cy="40" r="24" />
</svg> </body>
</html>
styling the SVG images的更多相关文章
- 推荐15款制作 SVG 动画的 JavaScript 库
在当今时代,SVG是最流行的和正在被众多的设计人员和开发人员使用,创建支持视网膜和响应式的网页设计.绘制SVG不是一个艰巨的任务,因为大量的 JavaScript 库可与 SVG 图像搭配使用.这些J ...
- [转]用CSS给SVG <use>的内容添加样式
来源:http://www.w3cplus.com/svg/styling-svg-use-content-css.html?utm_source=tuicool&utm_medium=ref ...
- 【转】Styling And Animating SVGs With CSS
原文转自:http://www.smashingmagazine.com/2014/11/03/styling-and-animating-svgs-with-css/?utm_source=CSS- ...
- CSS和SVG中的剪切——clip-path属性和<clipPath>元素
剪切是什么 剪切是一个图形化操作,你可以部分或者完全隐藏一个元素.被剪切的元素可以是一个容器也可以是一个图像元素.元素的哪些部分显示或隐藏是由剪切的路径来决定的. 剪切路径定义了一个区域,在这个区域内 ...
- 【转】CSS和SVG中的剪切——clip-path属性和<clipPath>元素
本文由大漠根据SaraSoueidan的<Clipping in CSS and SVG – The clip-path Property and <clipPath> Elemen ...
- HTML页面中嵌入SVG
HTML页面中嵌入SVG的几种方式 你有N种理由使用SVG在页面中展示图像,如它的矢量特性.广泛的浏览器支持.比JPEG和PNG更小的体积.可用CSS设置外观.使用DOM API操作以及各种可用的SV ...
- W3C推进SVG规范Ver1.1(中文译稿)—Part I
转自:http://www.gispark.com/html/GISarticle/2006/1215/826.html Scalable Vector Graphics (SVG) 1.1 Spec ...
- 【Web动画】SVG 实现复杂线条动画
在上一篇文章中,我们初步实现了一些利用基本图形就能完成的线条动画: [Web动画]SVG 线条动画入门 当然,事物都是朝着熵增焓减的方向发展的,复杂线条也肯定比有序线条要多. 很多时候,我们无法人工去 ...
- 【Web动画】SVG 线条动画入门
通常我们说的 Web 动画,包含了三大类. CSS3 动画 javascript 动画(canvas) html 动画(SVG) 个人认为 3 种动画各有优劣,实际应用中根据掌握情况作出取舍,本文讨论 ...
随机推荐
- Mac下利用SSH进行传输文件(转)
//1.从服务器上下载文件 scp username@servername:/path/filename /var/www/local_dir(本地目录) //例如scp root@192.168.0 ...
- css中奇怪的地方
1.border-color 继承内部元素前景色(color:black.可能对元素本身没有效果) 2.border-style:none;//不仅样式没了,border-width也变为0 ...
- 关联容器:unordered_map详细介绍(附可运行代码)
介绍 1 特性 2 Hashtable和bucket 模版 1 迭代器 功能函数 1 构造函数 12示例代码 2 容量操作 21 size 22 empty 3 元素操作 31 find 32 ins ...
- Chapter 7. Packages
Chapter 7. Packages The hierarchical naming structure for packages is intended to be convenient for ...
- JavaScript函数——闭包
闭包 概念 只有函数内部的子函数才能读取局部变量,所以闭包可以理解成"定义在一个函数内部的函数".在本质上,闭包是将函数内部和函数外部连接起来的桥梁 例子 function out ...
- [译]用R语言做挖掘数据《五》
介绍 一.实验说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou,密码shiyanlou 2. 环境介绍 本实验环境采用带桌面的Ubuntu Linux环境,实验中会用到程序: 1. ...
- WCF-异步调用和两种客户端形式
当发布一个服务端之后,客户端可以通过服务端的元数据,用VS2010添加服务引用的方式生成对应的代码.并且可以选择生成相应的异步操作. WCF实现代码,Add操作延时5秒后再返回结果. [Service ...
- SQL Serever学习13——数据库编程语言
编程基础 注释 注释命名来对一些语句进行说明,便于日后维护或者其他用户理解,注释不会执行. 单行注释 SELECT GETDATE() --查询当前日期 多行注释 /* 注释有助于 理解操作的内容 查 ...
- golang命令和VSCode配置
Go是一门全新的静态类型开发语言,具有自动垃圾回收.丰富的内置类型.函数多返回值.错误处理.匿名函数.并发编程.反射等特性 golang常用命令: go env #查看go的环境 echo %GORO ...
- 【转载】 历届Turing奖得主名单
Turing奖最早设立于1966年,是美国计算机协会在计算机技术方面所授予的最高奖项,被喻为计算机界的诺贝尔奖.它是以英国数学天才Alan Turing先生的名字命名的,Alan Turing先生对早 ...