📄 svg rect.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0043)http://www.w3school.com.cn/svg/svg_rect.asp -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>SVG <rect></TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-cn>
<META content=all name=robots>
<META content=w3school.com.cn name=author>
<META content="Copyright W3school.com.cn All Rights Reserved." name=Copyright>
<META content=true name=MSSmartTagsPreventParsing>
<META http-equiv=imagetoolbar content=false><LINK href="SVG rect_files/c1.css"
type=text/css rel=stylesheet>
<META content="MSHTML 6.00.3790.4134" name=GENERATOR></HEAD>
<BODY id=xml>
<DIV id=wrapper>
<DIV id=header>
<H1><A title=点击此处,返回首页
href="http://www.w3school.com.cn/index.html">w3school在线教程</A></H1></DIV>
<DIV id=navfirst>
<UL id=menu>
<LI id=h><A title=HTML教程 href="http://www.w3school.com.cn/h.asp">HTML教程</A>
</LI>
<LI id=x><A title=XML教程 href="http://www.w3school.com.cn/x.asp">XML教程</A>
</LI>
<LI id=b><A title=浏览器脚本 href="http://www.w3school.com.cn/b.asp">浏览器脚本</A>
</LI>
<LI id=s><A title=服务器脚本 href="http://www.w3school.com.cn/s.asp">服务器脚本</A>
</LI>
<LI id=d><A title="dot net教程" href="http://www.w3school.com.cn/d.asp">dot
net教程</A> </LI>
<LI id=m><A title=多媒体教程 href="http://www.w3school.com.cn/m.asp">多媒体教程</A>
</LI>
<LI id=w><A title=建站手册 href="http://www.w3school.com.cn/w.asp">建站手册</A>
</LI></UL></DIV>
<DIV id=navsecond>
<DIV id=course>
<H2>SVG 基础</H2>
<UL>
<LI><A title="SVG 首页" href="http://www.w3school.com.cn/svg/index.asp">SVG
首页</A>
<LI><A title="SVG 简介" href="http://www.w3school.com.cn/svg/svg_intro.asp">SVG
简介</A>
<LI><A title="SVG 实例"
href="http://www.w3school.com.cn/svg/svg_example.asp">SVG 实例</A>
<LI><A title=在HTML文档中的SVG
href="http://www.w3school.com.cn/svg/svg_inhtml.asp">SVG in HTML</A> </LI></UL>
<H2>SVG 形状</H2>
<UL>
<LI><A title="SVG 矩形" href="http://www.w3school.com.cn/svg/svg_rect.asp">SVG
矩形</A>
<LI><A title="SVG 圆形" href="http://www.w3school.com.cn/svg/svg_circle.asp">SVG
圆形</A>
<LI><A title="SVG 椭圆"
href="http://www.w3school.com.cn/svg/svg_ellipse.asp">SVG 椭圆</A>
<LI><A title="SVG 线条" href="http://www.w3school.com.cn/svg/svg_line.asp">SVG
线条</A>
<LI><A title="SVG 多边形"
href="http://www.w3school.com.cn/svg/svg_polygon.asp">SVG 多边形</A>
<LI><A title="SVG 折线"
href="http://www.w3school.com.cn/svg/svg_polyline.asp">SVG 折线</A>
<LI><A title="SVG 路径" href="http://www.w3school.com.cn/svg/svg_path.asp">SVG
路径</A> </LI></UL>
<H2>SVG 滤镜</H2>
<UL>
<LI><A title="SVG 滤镜简介"
href="http://www.w3school.com.cn/svg/svg_filters_intro.asp">SVG 滤镜简介</A>
<LI><A title="SVG 高斯滤镜"
href="http://www.w3school.com.cn/svg/svg_filters_gaussian.asp">SVG 高斯滤镜</A>
</LI></UL>
<H2>SVG 渐变</H2>
<UL>
<LI><A title="SVG 线形渐变"
href="http://www.w3school.com.cn/svg/svg_grad_linear.asp">SVG 线形渐变</A>
<LI><A title="SVG 放射渐变"
href="http://www.w3school.com.cn/svg/svg_grad_radial.asp">SVG 放射渐变</A>
</LI></UL>
<H2>SVG 实例</H2>
<UL>
<LI><A title="SVG 实例"
href="http://www.w3school.com.cn/svg/svg_examples.asp">SVG 实例</A> </LI></UL>
<H2>SVG 参考</H2>
<UL>
<LI><A title="SVG 元素"
href="http://www.w3school.com.cn/svg/svg_reference.asp">SVG 元素</A>
</LI></UL></DIV>
<DIV id=selected>
<H2>建站手册</H2>
<UL>
<LI><A title=网站构建 href="http://www.w3school.com.cn/site/index.asp">网站构建</A>
<LI><A title=W3C href="http://www.w3school.com.cn/w3c/index.asp">万维网联盟</A>
<LI><A title=浏览器信息
href="http://www.w3school.com.cn/browsers/index.asp">浏览器信息</A>
<LI><A title=网站品质 href="http://www.w3school.com.cn/quality/index.asp">网站品质</A>
<LI><A title=语义网 href="http://www.w3school.com.cn/semweb/index.asp">语义网</A>
<LI><A title=职业规划 href="http://www.w3school.com.cn/careers/index.asp">职业规划</A>
<LI><A title=网站主机 href="http://www.w3school.com.cn/hosting/index.asp">网站主机</A>
</LI></UL></DIV></DIV>
<DIV id=maincontent>
<H2>SVG <rect></H2>
<DIV id=tpn>
<UL class=prenext>
<LI class=pre><A href="http://www.w3school.com.cn/svg/svg_inhtml.asp">Previous
Page</A> </LI>
<LI class=next><A href="http://www.w3school.com.cn/svg/svg_circle.asp">Next
Page</A> </LI></UL></DIV>
<DIV class=intro>
<P><STRONG>SVG有一些预定义的形状元素,可被开发者使用和操作。</STRONG></P></DIV>
<DIV>
<H3>SVG 形状</H3>
<P>SVG有一些预定义的形状元素,可被开发者使用和操作:</P>
<UL>
<LI>矩形 <rect>
<LI>圆形 <circle>
<LI>椭圆 <ellipse>
<LI>线 <line>
<LI>折线 <polyline>
<LI>多边形 <polygon>
<LI>路径 <path> </LI></UL>
<P>下面的章节会为您讲解这些元素,首先从矩形元素开始。</P></DIV>
<DIV>
<H3><rect> 标签</H3>
<P><rect> 标签可用来创建矩形,以及矩形的变种。</P>
<P>要理解它的工作原理,请把这些代码拷贝到记事本,然后保存为"rect1.svg"文件。把此文件放入web目录中:</P><PRE><?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<rect width="300" height="100"
style="fill:rgb(0,0,255);stroke-width:1;
stroke:rgb(0,0,0)"/>
</svg></PRE>
<H4>代码解释:</H4>
<UL>
<LI>rect元素的 width 和 height 属性可定义矩形的高度和宽度
<LI>style 属性用来定义CSS属性
<LI>CSS 的 fill 属性定义矩形的填充颜色(rgb值、颜色名或者十六进制值)
<LI>CSS 的 stroke-width 属性定义举行边框的宽度
<LI>CSS 的 stroke 属性定义矩形边框的颜色 </LI></UL>
<P><A href="http://www.w3school.com.cn/svg/rect1.svg">查看此例</A></P>
<P>让我们看一下另一个包含新属性的例子:</P><PRE><?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="20" width="250" height="250"
style="fill:blue;stroke:pink;stroke-width:5;
fill-opacity:0.1;stroke-opacity:0.9"/>
</svg></PRE>
<H4>例子解释:</H4>
<UL>
<LI>x 属性定义举行的左侧位置(例如,x="0"定义矩形到浏览器窗口左侧的距离是0px)
<LI>y 属性定义举行的顶端位置(例如,y="0"定义矩形到浏览器窗口顶端的距离是0px)
<LI>CSS 的 fill-opacity 属性定义填充颜色透明度(合法的范围是:0 - 1)
<LI>CSS 的 stroke-opacity 属性定义笔触颜色的透明度(合法的范围是:0 - 1) </LI></UL>
<P><A href="http://www.w3school.com.cn/svg/rect2.svg">查看例子</A></P>
<P>为整个元素定义透明度:</P><PRE><?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="20" width="250" height="250"
style="fill:blue;stroke:pink;stroke-width:5;
opacity:0.9"/>
</svg></PRE>
<H4>代码解释:</H4>
<P>CSS 的 opacity 属性定义整个元素的透明值(合法的范围是:0 - 1)</P>
<P><A href="http://www.w3school.com.cn/svg/rect3.svg">查看例子</A></P>
<P>最后的例子,创建带有圆角的矩形:</P><PRE><?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="20" rx="20" ry="20" width="250"
height="100" style="fill:red;stroke:black;
stroke-width:5;opacity:0.5"/>
</svg></PRE>
<H4>代码解释:</H4>
<P>rx 和 ry 属性可使矩形产生圆角</P>
<P><A href="http://www.w3school.com.cn/svg/rect4.svg">查看例子</A></P></DIV>
<DIV id=bpn>
<UL class=prenext>
<LI class=pre><A href="http://www.w3school.com.cn/svg/svg_inhtml.asp">Previous
Page</A> </LI>
<LI class=next><A href="http://www.w3school.com.cn/svg/svg_circle.asp">Next
Page</A> </LI></UL></DIV></DIV>
<DIV id=sidebar>
<DIV id=searchui>
<FORM id=searchform action=http://www.google.com/search method=get>
<P><LABEL for=searched_content>Search:</LABEL></P>
<P><INPUT type=hidden value=www.w3school.com.cn name=sitesearch></P>
<P><INPUT class=box id=searched_content title=在此输入搜索内容。 name=as_q> <INPUT class=button title=搜索! type=submit value=Go> </P></FORM></DIV>
<DIV id=tools>
<H5 id=tools_reference><A
href="http://www.w3school.com.cn/svg/svg_reference.asp">SVG 参考手册</A></H5>
<H5 id=tools_example><A
href="http://www.w3school.com.cn/example/svge_examples.asp">SVG
实例</A></H5></DIV>
<DIV id=books></DIV></DIV>
<DIV id=footer>
<P>W3School提供的内容仅用于培训。我们不保证内容的正确性。通过使用本站内容随之而来的风险与本站无关。当使用本站时,代表您已接受了本站的使用条款和隐私条款。</P>
<P>版权所有,保留一切权利。未经书面许可,不得转载。W3School(s)简体中文版授权上海蒙信网络科技有限公司在中华人民共和国运营。</P></DIV></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -