﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-RTY 实践出真知-随笔分类-CSS</title><link>http://www.cppblog.com/lauer3912/category/16447.html</link><description>没有理由不学习</description><language>zh-cn</language><lastBuildDate>Sun, 20 Jul 2014 18:34:00 GMT</lastBuildDate><pubDate>Sun, 20 Jul 2014 18:34:00 GMT</pubDate><ttl>60</ttl><item><title>分享60个来自Picons.me的全格式社交图标库</title><link>http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sun, 25 Sep 2011 01:37:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156742.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156742.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156742.html</trackback:ping><description><![CDATA[原文位置：<a href="http://www.gbin1.com/tools/design/60socialiconsinallpopularformatsbypiconsme/">http://www.gbin1.com/tools/design/60socialiconsinallpopularformatsbypiconsme/<br /><span class="Apple-style-span" style="color: #bbbbbb; font-family: arial; font-size: 13px; line-height: 26px; -webkit-text-decorations-in-effect: none; background-color: #202020; "><p style="outline-width: medium; outline-style: none; outline-color: initial; ">图标设计公司Picons.me免费提供了一套60枚的图标库，这套图标支持所有的流行社交网络，并且支持多种格式：AI，EPS，PDF</p><p style="outline-width: medium; outline-style: none; outline-color: initial; ">同时有PSD和CSH格式以及不同大小的PNG格式（从16*16到512*512）。</p><p style="outline-width: medium; outline-style: none; outline-color: initial; ">最后提示，GBin1为了不让用户出现困惑，Picons.me的授权不包括这套社交图标。</p><p style="outline-width: medium; outline-style: none; outline-color: initial; "><img src="http://www.gbin1.com/backup/gbin1/generated/tools/design/60socialiconsinallpopularformatsbypiconsme/1.jpg/com.gbin1.core.ResizedThumbnail/resized1324307194.jpg" alt="" width="520" style="outline-width: medium; outline-style: none; outline-color: initial; border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-top-color: #333333; border-right-color: #333333; border-bottom-color: #333333; border-left-color: #333333; " /></p><p style="outline-width: medium; outline-style: none; outline-color: initial; "><a href="http://picons.me/download-social.php" target="_blank" style="outline-width: medium; outline-style: none; outline-color: initial; color: #2b99e6; text-decoration: none; ">下载地址</a></p></span><br /></a><img src ="http://www.cppblog.com/lauer3912/aggbug/156742.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-25 09:37 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分享35个高品质的PSD版本UI网页设计</title><link>http://www.cppblog.com/lauer3912/archive/2011/09/25/156740.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sun, 25 Sep 2011 01:31:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/25/156740.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156740.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/25/156740.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156740.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156740.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://sixrevisions.com/freebies/web-page-templates/transparent-glass-ui/This free user interface pack, brought to you by&nbsp;PixelsDaily, includes a variety of popular elements used in web applicati...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/09/25/156740.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/156740.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-25 09:31 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/25/156740.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS2 参考手册</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147526.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:26:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147526.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147526.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147526.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147526.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147526.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 请点击表格中属性列的链接，可以查看相关属性的详细信息。CSS 属性组：背景文本字体边框和轮廓外边距内边距列表内容生成尺寸定位打印表格伪类伪元素提示和注释：属性：&#8220;属性&#8221; 列指向语法、实例、浏览器支持等内容。CSS："CSS" 列指示属性是在哪个 CSS 版本中定义的（CSS1 还是 CSS2）。提示：W3School 的 CSS 参考手册定期在所有主流浏览器中进行测试。最后...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/05/28/147526.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/147526.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:26 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147526.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS2 打印参考]</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147525.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:25:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147525.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147525.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147525.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147525.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147525.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>打印属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">打印 HTML 文档总是会出现问题。在 CSS2 中，我们可以借助打印属性让打印 web 内容更容易一些。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">值</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">orphans</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素放在页面底部时所允许的最少文本行数。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">number</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">marks</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">设置是否在内容区之外但是在画布的可打印区域内放&#8220;十字标志&#8221;。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; line-height: 18px; ">请注意，CSS2.1 已删除该属性。</p></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><ul style="margin-top: 0px; margin-bottom: 0px; list-style-type: none; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">none</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">crop</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">cross</li></ul></td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">page</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个属性与 size 属性结合可以指定打印一个元素时所用的特定页面类型。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; line-height: 18px; ">请注意，CSS2.1 已删除该属性。</p></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">auto identifier</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_print_page-break-after.asp" title="CSS page-break-after 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">page-break-after</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素后是否应当放置分页符。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><ul style="margin-top: 0px; margin-bottom: 0px; list-style-type: none; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">auto</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">always</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">avoid</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">left</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">right</li></ul></td></tr><tr><td style="white-space: nowrap; vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_print_page-break-before.asp" title="CSS page-break-before 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">page-break-before</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素前否应当放置分页符。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><ul style="margin-top: 0px; margin-bottom: 0px; list-style-type: none; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">auto</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">always</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">avoid</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">left</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">right</li></ul></td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_print_page-break-inside.asp" title="CSS page-break-inside 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">page-break-inside</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素内部是否应当放置分页符。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><ul style="margin-top: 0px; margin-bottom: 0px; list-style-type: none; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">auto</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">avoid</li></ul></td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">size</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">利用这个属性，创作人员可以声明打印一个元素时所用页框的大小和方向。它可以与 page 结合使用。不过并不要求一定如此。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; line-height: 18px; ">请注意，CSS2.1 已删除该属性。</p></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><ul style="margin-top: 0px; margin-bottom: 0px; list-style-type: none; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">auto</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">portrait</li><li style="margin-top: 0px; list-style-type: none; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">landscape</li></ul></td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">widows</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素放在页面顶部时所允许的最少文本行数。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">number</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147525.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:25 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147525.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS2 听觉参考</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147524.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:24:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147524.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147524.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147524.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147524.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147524.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 听觉样式表听觉样式表可把语音合成与音响效果相组合，使用户可以听到信息，而无需进行阅读。听觉呈现可用于：视觉能力低弱的人士帮助用户学习阅读帮助有阅读障碍的用户家庭娱乐在汽车中使用听觉呈现通常会把文档转化为纯文本，然后传给屏幕阅读器（可读出屏幕上所有字符的一种程序）。听觉样式表的一个例子：h1, h2, h3, h4 { voice-family: male; richness: 80; cue-be...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/05/28/147524.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/147524.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:24 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147524.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 单位</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147523.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:24:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147523.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147523.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147523.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147523.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147523.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>尺寸</h2><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 112px; ">单位</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">%</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">百分比</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">in</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">英寸</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">cm</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">厘米</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">mm</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">毫米</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">em</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">1em 等于当前的字体尺寸。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; line-height: 18px; ">2em 等于当前字体尺寸的两倍。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; line-height: 18px; ">例如，如果某元素以 12pt 显示，那么 2em 是24pt。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; line-height: 18px; ">在 CSS 中，em 是非常有用的单位，因为它可以自动适应用户所使用的字体。</p></td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">ex</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">一个 ex 是一个字体的 x-height。 (x-height 通常是字体尺寸的一半。)</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">pt</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">磅 (1 pt 等于 1/72 英寸)</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">pc</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">12 点活字 (1 pc 等于 12 点)</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">px</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">像素 (计算机屏幕上的一个点)</td></tr></tbody></table></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>颜色</h2><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 112px; ">单位</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">(颜色名)</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">颜色名称 (比如 red)</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">rgb(x,x,x)</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">RGB 值 (比如 #ff0000)</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">rgb(x%, x%, x%)</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">RGB 百分比值 (比如 rgb(100%,0%,0%))</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">#rrggbb</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">十六进制数 (比如 #ff0000)</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147523.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:24 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147523.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS2 媒介类型</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147522.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:22:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147522.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147522.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147522.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147522.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147522.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">媒介类型(Media Types)允许你定义以何种媒介来提交文档。文档可以被显示在显示器、纸媒介或者听觉浏览器等等。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>媒介类型</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">某些 CSS 属性仅仅被设计为针对某些媒介。比方说 "voice-family" 属性被设计为针对听觉用户终端。其他的属性可被用于不同的媒介。例如，"font-size" 属性可被用于显示器以及印刷媒介，但是也许会带有不同的值。显示器上面的显示的文档通常会需要比纸媒介文档更大的字号，同时，在显示器上，sans-serif 字体更易阅读，而在纸媒介上，serif 字体更易阅读。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>@media规则</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">@media 规则使你有能力在相同的样式表中，使用不同的样式规则来针对不同的媒介。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面这个例子中的样式告知浏览器在显示器上显示 14 像素的 Verdana 字体。但是假如页面需要被打印，将使用 10 个像素的 Times 字体。注意：font-weight 被设置为粗体，不论显示器还是纸媒介：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;html&gt; &lt;head&gt;  &lt;style&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">@media screen</code> { p.test {font-family:verdana,sans-serif; font-size:14px} }  <code style="font-family: 'Courier New', monospace; color: #0000ff; ">@media print</code> { p.test {font-family:times,serif; font-size:10px} }  <code style="font-family: 'Courier New', monospace; color: #0000ff; ">@media screen,print</code> { p.test {font-weight:bold} } &lt;/style&gt;  &lt;/head&gt;  &lt;body&gt;....&lt;/body&gt;  &lt;/html&gt;</pre></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>不同的媒介类型</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">注释：</span>媒介类型名称对大小写不敏感。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">媒介类型</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">all</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于所有的媒介设备。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">aural</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于语音和音频合成器。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">braille</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于盲人用点字法触觉回馈设备。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">embossed</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于分页的盲人用点字法打印机。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">handheld</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于小的手持的设备。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">print</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于打印机。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">projection</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于方案展示，比如幻灯片。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">screen</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于电脑显示器。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">tty</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于使用固定密度字母栅格的媒介，比如电传打字机和终端。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">tv</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">用于电视机类型的设备。</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147522.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:22 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147522.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 分类 (Classification)</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147521.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:21:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147521.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147521.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147521.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147521.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147521.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 分类属性允许你规定如何以及在何处显示元素。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS分类(Classification)实例：</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_display" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">如何把元素显示为内联元素</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何把元素显示为内联元素。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_display_block" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">如何把元素显示为块级元素</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何把元素显示为块级元素。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">float 属性的简单应用</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使图像浮动于一个段落的右侧。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">将带有边框和边界的图像浮动于段落的右侧</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使图像浮动于段落的右侧。向图像添加边框和边界。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float3" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">带标题的图像浮动于右侧</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使带有标题的图像浮动于右侧</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float4" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使段落的首字母浮动于左侧</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使段落的首字母浮动于左侧，并向这个字母添加样式。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float5" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">创建水平菜单</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使用具有一栏超链接的浮动来创建水平菜单。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float6" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">创建无表格的首页</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使用浮动来创建拥有页眉、页脚、左侧目录和主体内容的首页。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_relative" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：相对定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何相对于一个元素的正常位置来对其定位。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_absolute" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：绝对定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用绝对值来对元素进行定位。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_fixed" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：固定定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何相对于浏览器窗口来对元素进行定位。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_visibility" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">如何使元素不可见</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使元素不可见。你希望元素被显示出来，还是不呢？</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_visibility_collapse" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">把表格元素设置为 collapse（请在非 IE 的浏览器中查看）</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使表格元素叠加？</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_cursor" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">改变光标</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何改变光标。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_class-clear" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">清除元素的侧面</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用清除元素侧面的浮动元素。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 分类属性 (Classification)</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 分类属性允许你控制如何显示元素，设置图像显示于另一元素中的何处，相对于其正常位置来定位元素，使用绝对值来定位元素，以及元素的可见度。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_clear.asp" title="CSS clear 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">clear</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置一个元素的侧面是否允许其他的浮动元素。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_cursor.asp" title="CSS cursor 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">cursor</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">规定当指向某元素之上时显示的指针类型。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_display.asp" title="CSS display 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">display</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置是否及如何显示元素。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_float.asp" title="CSS float 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">float</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">定义元素在哪个方向浮动。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_position.asp" title="CSS position 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">position</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">把元素放置到一个静态的、相对的、绝对的、或固定的位置中。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_visibility.asp" title="CSS visibility 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">visibility</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素是否可见或不可见。</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147521.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:21 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147521.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 尺寸 (Dimension)</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147520.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:21:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147520.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147520.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147520.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147520.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147520.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度。同样，它允许你增加行间距。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 尺寸实例：</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_height" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值设置图像的高度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值设置元素的高度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_height_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比设置图像的高度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置元素的高度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_width" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值来设置元素的宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值来设置元素的宽度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_width_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比来设置元素的宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置元素的宽度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_max-height" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置元素的最大高度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置一个元素的最大高度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_max-width" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值来设置元素的最大宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值来设置元素的最大高度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_max-width_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比来设置元素的最大宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置元素的最大高度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_min-height" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值来设置元素的最小高度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值来设置元素的最小高度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_min-width" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值来设置元素的最小宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值来设置元素的最小宽度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_min-width_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比来设置元素的最小宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置元素的最小宽度。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_line-height_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比设置行间距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置段落中的行间距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_line-height_pixel" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值设置行间距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值来设置段落中的行间距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_dim_line-height_number" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用数值来设置行间距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用一个数值来设置段落中的行间距。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 尺寸属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 尺寸属性允许你控制元素的高度和宽度。同样，还允许你增加行间距。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_height.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">height</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的高度。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_line-height.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">line-height</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置行高。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_max-height.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">max-height</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的最大高度。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_max-width.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">max-width</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的最大宽度。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_min-height.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">min-height</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的最小高度。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_min-width.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">min-width</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的最小宽度。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_dim_width.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">width</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的宽度。</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147520.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:21 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147520.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 伪元素 (Pseudo-elements)</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147518.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:20:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147518.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147518.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147518.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147518.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147518.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 伪元素用于向某些选择器设置特殊效果。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>语法</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">伪元素的语法：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">selector:pseudo-element {property:value;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 类也可以与伪元素配合使用：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">selector.class:pseudo-element {property:value;}</pre></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>:first-line 伪元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">"first-line" 伪元素用于向文本的首行设置特殊样式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在下面的例子中，浏览器会根据 "first-line" 伪元素中的样式对 p 元素的第一行文本进行格式化：</p><h3>实例</h3><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p:first-line   {   color:#ff0000;   font-variant:small-caps;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_firstline" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>"first-line" 伪元素只能用于块级元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>下面的属性可应用于 "first-line" 伪元素：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; ">font</li><li style="margin-top: 3px; ">color</li><li style="margin-top: 3px; ">background</li><li style="margin-top: 3px; ">word-spacing</li><li style="margin-top: 3px; ">letter-spacing</li><li style="margin-top: 3px; ">text-decoration</li><li style="margin-top: 3px; ">vertical-align</li><li style="margin-top: 3px; ">text-transform</li><li style="margin-top: 3px; ">line-height</li><li style="margin-top: 3px; ">clear</li></ul></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>:first-letter 伪元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">"first-letter" 伪元素用于向文本的首字母设置特殊样式：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p:first-letter   {   color:#ff0000;   font-size:xx-large;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_firstletter" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>"first-letter" 伪元素只能用于块级元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>下面的属性可应用于 "first-letter" 伪元素：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; ">font</li><li style="margin-top: 3px; ">color</li><li style="margin-top: 3px; ">background</li><li style="margin-top: 3px; ">margin</li><li style="margin-top: 3px; ">padding</li><li style="margin-top: 3px; ">border</li><li style="margin-top: 3px; ">text-decoration</li><li style="margin-top: 3px; ">vertical-align (仅当 float 为 none 时)</li><li style="margin-top: 3px; ">text-transform</li><li style="margin-top: 3px; ">line-height</li><li style="margin-top: 3px; ">float</li><li style="margin-top: 3px; ">clear</li></ul></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>伪元素和 CSS 类</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">伪元素可以与 CSS 类配合使用：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; "><code style="font-family: 'Courier New', monospace; color: #0000ff; ">p.article:first-letter</code>   {   color: #FF0000;   }  &lt;p <span style="color: #ff0000; ">class="article"</span>&gt;This is a paragraph in an article。&lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">上面的例子会使所有 class 为 article 的段落的首字母变为红色。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>多重伪元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">可以结合多个伪元素来使用。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在下面的例子中，段落的第一个字母将显示为红色，其字体大小为 xx-large。第一行中的其余文本将为蓝色，并以小型大写字母显示。段落中的其余文本将以默认字体大小和颜色来显示：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p:first-letter   {   color:#ff0000;   font-size:xx-large;   }  p:first-line   {   color:#0000ff;   font-variant:small-caps;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_firstletter_firstline" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS2 - :before 伪元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">":before" 伪元素可以在元素的内容前面插入新内容。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的例子在每个 &lt;h1&gt; 元素前面插入一幅图片：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1:before   {   content:url(logo.gif);   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_before" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS2 - :after 伪元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">":after" 伪元素可以在元素的内容之后插入新内容。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的例子在每个 &lt;h1&gt; 元素后面插入一幅图片：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1:after   {   content:url(logo.gif);   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_after" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>伪元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><em style="font-style: normal; font-weight: bold; ">W3C</em>："W3C" 列指示出该属性在哪个 CSS 版本中定义（CSS1 还是 CSS2）。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 156px; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 363px; ">描述</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 24px; ">CSS</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_first-letter.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:first-letter</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向文本的第一个字母添加特殊样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">1</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_first-line.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:first-line</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向文本的首行添加特殊样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">1</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_before.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:before</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">在元素之前添加内容。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_after.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:after</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">在元素之后添加内容。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147518.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:20 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147518.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 伪类 (Pseudo-classes)</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147517.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:19:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147517.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147517.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147517.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147517.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147517.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 伪类用于向某些选择器添加特殊的效果。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 伪类 (Pseudo-classes)实例：</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_link" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">超链接</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何向文档中的超链接添加不同的颜色。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_link2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">超链接 2</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何向超链接添加其他样式。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_link_focus" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">超链接 - :focus 的使用</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何对超链接应用 :focus 伪类（无法在 IE 中工作）。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_first-child" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:first-child（首个子对象）</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示 :first-child 伪类的用法。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_lang" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:lang（语言）</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示 :lang 伪类的用法。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>语法</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">伪类的语法：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">selector : pseudo-class {property: value}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 类也可与伪类搭配使用。</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">selector.class : pseudo-class {property: value}</pre></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>锚伪类</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在支持 CSS 的浏览器中，链接的不同状态都可以不同的方式显示，这些状态包括：活动状态，已被访问状态，未被访问状态，和鼠标悬停状态。</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; "><code style="font-family: 'Courier New', monospace; color: #0000ff; ">a:link</code> {color: #FF0000}		<span style="color: #999999; ">/* 未访问的链接 */</span> <code style="font-family: 'Courier New', monospace; color: #0000ff; ">a:visited</code> {color: #00FF00}	<span style="color: #999999; ">/* 已访问的链接 */</span> <code style="font-family: 'Courier New', monospace; color: #0000ff; ">a:hover</code> {color: #FF00FF}	<span style="color: #999999; ">/* 鼠标移动到链接上 */</span> <code style="font-family: 'Courier New', monospace; color: #0000ff; ">a:active</code> {color: #0000FF}	<span style="color: #999999; ">/* 选定的链接 */</span> </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_link" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>在 CSS 定义中，a:hover 必须被置于 a:link 和 a:visited 之后，才是有效的。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>在 CSS 定义中，a:active 必须被置于 a:hover 之后，才是有效的。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>伪类名称对大小写不敏感。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>伪类与 CSS 类</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">伪类可以与 CSS 类配合使用：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">a<code style="font-family: 'Courier New', monospace; color: #0000ff; ">.red</code> : visited {color: #FF0000}  &lt;a class="<code style="font-family: 'Courier New', monospace; color: #0000ff; ">red</code>" href="css_syntax.asp"&gt;CSS Syntax&lt;/a&gt;</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假如上面的例子中的链接被访问过，那么它将显示为红色。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS2 - :first-child 伪类</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您可以使用 :first-child 伪类来选择元素的第一个子元素。这个特定伪类很容易遭到误解，所以有必要举例来说明。考虑以下标记：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;div&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;p&gt;These are the necessary steps:&lt;/p&gt;</code> &lt;ul&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;li&gt;Intert Key&lt;/li&gt;</code> &lt;li&gt;Turn key <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;strong&gt;clockwise&lt;/strong&gt;</code>&lt;/li&gt; &lt;li&gt;Push accelerator&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Do <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;em&gt;not&lt;/em&gt;</code> push the brake at the same time as the accelerator.&lt;/p&gt; &lt;/div&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在上面的例子中，作为第一个元素的元素包括第一个 p、第一个 li 和 strong 和 em 元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">给定以下规则：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p:first-child {font-weight: bold;} li:first-child {text-transform:uppercase;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">第一个规则将作为某元素第一个子元素的所有 p 元素设置为粗体。第二个规则将作为某个元素（在 HTML 中，这肯定是 ol 或 ul 元素）第一个子元素的所有 li 元素变成大写。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请访问该链接，来查看这个&nbsp;<a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_first-child" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:first-child 实例</a>的效果。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>最常见的错误是认为 p:first-child 之类的选择器会选择 p 元素的第一个子元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>必须声明&nbsp;<a href="http://www.w3school.com.cn/tags/tag_doctype.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">&lt;!DOCTYPE&gt;</a>，这样 :first-child 才能在 IE 中生效。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">为了使您更透彻地理解 :first-child 伪类，我们另外提供了 3 个例子：</p><h3>例子 1 - 匹配第一个 &lt;p&gt; 元素</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在下面的例子中，选择器匹配作为任何元素的第一个子元素的 p 元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">p:first-child</code> {   color: red;   }  &lt;/style&gt; &lt;/head&gt;  &lt;body&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;p&gt;some text&lt;/p&gt;</code> &lt;p&gt;some text&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_first-child_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">TIY</a></p><h3>例子 2 - 匹配所有 &lt;p&gt; 元素中的第一个 &lt;i&gt; 元素</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在下面的例子中，选择器匹配所有 &lt;p&gt; 元素中的第一个 &lt;i&gt; 元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">p &gt; i:first-child</code> {   font-weight:bold;   }  &lt;/style&gt; &lt;/head&gt;  &lt;body&gt; &lt;p&gt;some <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;i&gt;text&lt;/i&gt;</code>. some &lt;i&gt;text&lt;/i&gt;.&lt;/p&gt; &lt;p&gt;some <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;i&gt;text&lt;/i&gt;</code>. some &lt;i&gt;text&lt;/i&gt;.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_first-child_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">TIY</a></p><h3>例子 3 - 匹配所有作为第一个子元素的 &lt;p&gt; 元素中的所有 &lt;i&gt; 元素</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在下面的例子中，选择器匹配所有作为元素的第一个子元素的 &lt;p&gt; 元素中的所有 &lt;i&gt; 元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">p:first-child i</code> {   color:blue;   }  &lt;/style&gt; &lt;/head&gt;  &lt;body&gt; &lt;p&gt;some <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;i&gt;text&lt;/i&gt;</code>. some <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;i&gt;text&lt;/i&gt;</code>.&lt;/p&gt; &lt;p&gt;some &lt;i&gt;text&lt;/i&gt;. some &lt;i&gt;text&lt;/i&gt;.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_first-child_3" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">TIY</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS2 - :lang 伪类</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">:lang 伪类使你有能力为不同的语言定义特殊的规则。在下面的例子中，:lang 类为属性值为 no 的 q 元素定义引号的类型：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;html&gt; &lt;head&gt;  &lt;style type="text/css"&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">q:lang(no)    {    quotes: "~" "~"    }</code> &lt;/style&gt;  &lt;/head&gt;  &lt;body&gt; &lt;p&gt;文字&lt;q <code style="font-family: 'Courier New', monospace; color: #0000ff; ">lang="no"</code>&gt;段落中的引用的文字&lt;/q&gt;文字&lt;/p&gt; &lt;/body&gt;&lt;/html&gt;</pre></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>伪类</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><em style="font-style: normal; font-weight: bold; ">W3C</em>："W3C" 列指示出该属性在哪个 CSS 版本中定义（CSS1 还是 CSS2）。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 156px; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 363px; ">描述</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 24px; ">CSS</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_active.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:active</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向被激活的元素添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">1</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_focus.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:focus</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向拥有键盘输入焦点的元素添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_hover.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:hover</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">当鼠标悬浮在元素上方时，向元素添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">1</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_link.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:link</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向未被访问的链接添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">1</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_visited.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:visited</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向已被访问的链接添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">1</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_first-child.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:first-child</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向元素的第一个子元素添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pseudo_lang.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">:lang</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">向带有指定 lang 属性的元素添加样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147517.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:19 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147517.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 相邻兄弟选择器</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147516.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:18:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147516.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147516.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147516.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147516.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147516.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">相邻兄弟选择器（Adjacent sibling selector）可选择紧接在另一元素后的元素，且二者有相同父元素。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>选择相邻兄弟</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果需要选择紧接在另一个元素后的元素，而且二者有相同的父元素，可以使用相邻兄弟选择器（Adjacent sibling selector）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，如果要增加紧接在 h1 元素后出现的段落的上边距，可以这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 + p {margin-top:50px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个选择器读作：&#8220;选择紧接在 h1 元素后出现的段落，h1 和 p 元素拥有共同的父元素&#8221;。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_adjacent_sibling" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>语法解释</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">相邻兄弟选择器使用了加号（+），即相邻兄弟结合符（Adjacent sibling combinator）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>与子结合符一样，相邻兄弟结合符旁边可以有空白符。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请看下面这个文档树片段：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;div&gt;   &lt;ul&gt;     &lt;li&gt;List item 1&lt;/li&gt;     &lt;li&gt;List item 2&lt;/li&gt;     &lt;li&gt;List item 3&lt;/li&gt;   &lt;/ul&gt;   &lt;ol&gt;     &lt;li&gt;List item 1&lt;/li&gt;     &lt;li&gt;List item 2&lt;/li&gt;     &lt;li&gt;List item 3&lt;/li&gt;   &lt;/ol&gt; &lt;/div&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在上面的片段中，div 元素中包含两个列表：一个无序列表，一个有序列表，每个列表都包含三个列表项。这两个列表是相邻兄弟，列表项本身也是相邻兄弟。不过，第一个列表中的列表项与第二个列表中的列表项不是相邻兄弟，因为这两组列表项不属于同一父元素（最多只能算堂兄弟）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请记住，用一个结合符只能选择两个相邻兄弟中的第二个元素。请看下面的选择器：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">li + li {font-weight:bold;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">上面这个选择器只会把列表中的第二个和第三个列表项变为粗体。第一个列表项不受影响。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_adjacent_sibling_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>结合其他选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">相邻兄弟结合符还可以结合其他结合符：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">html &gt; body table + ul {margin-top:20px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个选择器解释为：选择紧接在 table 元素后出现的所有兄弟 ul 元素，该 table 元素包含在一个 body 元素中，body 元素本身是 html 元素的子元素。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147516.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:18 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147516.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 子元素选择器</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147514.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:18:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147514.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147514.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147514.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147514.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147514.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; line-height: normal;"><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-bottom:0pt; margin-top:0pt; "><a href="http://www.zhixian.com.cn/"><span style=" color:#0000ff; text-decoration:underline ;font-family:'宋体'; ">上海装修公司</span></a><a href="http://www.zhixian.com.cn/"><span style=" color:#0000ff; text-decoration:underline ;font-family:'宋体'; ">http://www.zhixian.com.cn/</span></a><span style=" font-size:10.5000pt; font-family:'宋体'; ">装修公司</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">与后代选择器相比，子元素选择器（Child selectors）只能选择作为某元素子元素的元素。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>选择子元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果您不希望选择任意的后代元素，而是希望缩小范围，只选择某个元素的子元素，请使用子元素选择器（Child selector）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，如果您希望选择只作为 h1 元素子元素的 strong 元素，可以这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 <span style="color: #ff0000; ">&gt;</span> strong {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个规则会把第一个 h1 下面的 strong 元素变为红色，但是第二个 strong 不受影响：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;h1&gt;This is &lt;strong&gt;very&lt;/strong&gt; important.&lt;/h1&gt; &lt;h1&gt;This is &lt;em&gt;really &lt;strong&gt;very&lt;/strong&gt;&lt;/em&gt; important.&lt;/h1&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_child" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>语法解释</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您应该已经注意到了，子选择器使用了大于号（子结合符）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">子结合符两边可以有空白符，这是可选的。因此，以下写法都没有问题：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 &gt; strong h1&gt; strong h1 &gt;strong h1&gt;strong </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果从右向左读，选择器 h1 &gt; strong 可以解释为&#8220;选择作为 h1 元素子元素的所有 strong 元素&#8221;。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>结合后代选择器和子选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请看下面这个选择器：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">table.company td &gt; p</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的选择器会选择作为 td 元素子元素的所有 p 元素，这个 td 元素本身从 table 元素继承，该 table 元素有一个包含 company 的 class 属性。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "><br /></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147514.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:18 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147514.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 后代选择器</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147513.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:17:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147513.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147513.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147513.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147513.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147513.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">后代选择器（descendant selector）又称为包含选择器。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">后代选择器可以选择作为某元素后代的元素。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>根据上下文选择元素</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">我们可以定义后代选择器来创建一些规则，使这些规则在某些文档结构中起作用，而在另外一些结构中不起作用。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">举例来说，如果您希望只对 h1 元素中的 em 元素应用样式，可以这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 em {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">上面这个规则会把作为 h1 元素后代的 em 元素的文本变为 红色。其他 em 文本（如段落或块引用中的 em）则不会被这个规则选中：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;h1&gt;This is a &lt;em&gt;important&lt;/em&gt; heading&lt;/h1&gt; &lt;p&gt;This is a &lt;em&gt;important&lt;/em&gt; paragraph.&lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_descendant_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">当然，您也可以在 h1 中找到的每个 em 元素上放一个 class 属性，但是显然，后代选择器的效率更高。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>语法解释</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在后代选择器中，规则左边的选择器一端包括两个或多个用空格分隔的选择器。选择器之间的空格是一种结合符（combinator）。每个空格结合符可以解释为&#8220;... 在 ... 找到&#8221;、&#8220;... 作为 ... 的一部分&#8221;、&#8220;... 作为 ... 的后代&#8221;，但是要求必须从右向左读选择器。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">因此，h1 em 选择器可以解释为 &#8220;作为 h1 元素后代的任何 em 元素&#8221;。如果要从左向右读选择器，可以换成以下说法：&#8220;包含 em 的所有 h1 会把以下样式应用到该 em&#8221;。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>具体应用</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">后代选择器的功能极其强大。有了它，可以使 HTML 中不可能实现的任务成为可能。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设有一个文档，其中有一个边栏，还有一个主区。边栏的背景为蓝色，主区的背景为白色，这两个区都包含链接列表。不能把所有链接都设置为蓝色，因为这样一来边栏中的蓝色链接都无法看到。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">解决方法是使用后代选择器。在这种情况下，可以为包含边栏的 div 指定值为 sidebar 的 class 属性，并把主区的 class 属性值设置为 maincontent。然后编写以下样式：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">div.sidebar {background:blue;} div.maincontent {background:white;} div.sidebar a:link {color:white;} div.maincontent a:link {color:blue;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">有关后代选择器有一个易被忽视的方面，即两个元素之间的层次间隔可以使无限的。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，如果写作 ul em，这个语法就会选择从 ul 元素继承的所有 em 元素，而不论 em 的嵌套层次多深。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">因此，ul em 将会选择以下标记中的所有 em 元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;ul&gt;   &lt;li&gt;List item 1     &lt;ol&gt;       &lt;li&gt;List item 1-1&lt;/li&gt;       &lt;li&gt;List item 1-2&lt;/li&gt;       &lt;li&gt;List item 1-3         &lt;ol&gt;           &lt;li&gt;List item 1-3-1&lt;/li&gt;           &lt;li&gt;List item <span style="color: #ff0000; ">&lt;em&gt;1-3-2&lt;/em&gt;</span>&lt;/li&gt;           &lt;li&gt;List item 1-3-3&lt;/li&gt;         &lt;/ol&gt;       &lt;/li&gt;       &lt;li&gt;List item 1-4&lt;/li&gt;     &lt;/ol&gt;   &lt;/li&gt;   &lt;li&gt;List item 2&lt;/li&gt;   &lt;li&gt;List item 3&lt;/li&gt; &lt;/ul&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_descendant" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147513.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:17 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147513.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 属性选择器详解</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147512.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:17:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147512.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147512.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147512.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147512.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147512.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 2 引入了属性选择器。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">属性选择器可以根据元素的属性及属性值来选择元素。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>简单属性选择</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果希望选择有某个属性的元素，而不论属性值是什么，可以使用简单属性选择器。</p><h3>例子 1</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果您希望把包含标题（title）的所有元素变为红色，可以写作：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">*[title] {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_att" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>例子 2</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">与上面类似，可以只对有 href 属性的锚（a 元素）应用样式：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">a[href] {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_att_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>例子 3</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">还可以根据多个属性进行选择，只需将属性选择器链接在一起即可。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，为了将同时有 href 和 title 属性的 HTML 超链接的文本设置为红色，可以这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">a[href][title] {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_att_3" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>例子 4</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">可以采用一些创造性的方法使用这个特性。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，可以对所有带有 alt 属性的图像应用样式，从而突出显示这些有效的图像：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">img[alt] {border: 5px solid red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_att_4" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>上面这个特例更适合用来诊断而不是设计，即用来确定图像是否确实有效。</p><h3>例子 5：为 XML 文档使用属性选择器</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">属性选择器在 XML 文档中相当有用，因为 XML 语言主张要针对元素和属性的用途指定元素名和属性名。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设我们为描述太阳系行星设计了一个 XML 文档。如果我们想选择有 moons 属性的所有 planet 元素，使之显示为红色，以便能更关注有 moons 的行星，就可以这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">planet[moons] {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这会让以下标记片段中的第二个和第三个元素的文本显示为红色，但第一个元素的文本不是红色：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;planet&gt;Venus&lt;/planet&gt; &lt;planet <span style="color: #ff0000; ">moons="1"</span>&gt;Earth&lt;/planet&gt; &lt;planet <span style="color: #ff0000; ">moons="2"</span>&gt;Mars&lt;/planet&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/css/planetml_attselector_att.xml" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">查看效果</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>根据具体属性值选择</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">除了选择拥有某些属性的元素，还可以进一步缩小选择范围，只选择有特定属性值的元素。</p><h3>例子 1</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，假设希望将指向 Web 服务器上某个指定文档的超链接变成红色，可以这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">a[href="http://www.w3school.com.cn/about_us.asp"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_value_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>例子 2</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">与简单属性选择器类似，可以把多个属性-值选择器链接在一起来选择一个文档。</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">a[href="http://www.w3school.com.cn/"][title="W3School"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这会把以下标记中的第一个超链接的文本大小加倍，但是第二个或第三个链接不受影响：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;a <span style="color: #ff0000; ">href="http://www.w3school.com.cn/"</span> <span style="color: #ff0000; ">title="W3School"</span>&gt;W3School&lt;/a&gt; &lt;a href="http://www.w3school.com.cn/css/" title="CSS"&gt;CSS&lt;/a&gt; &lt;a href="http://www.w3school.com.cn/html/" title="HTML"&gt;HTML&lt;/a&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_value_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>例子 3</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">同样地，XML 语言也可以利用这种方法来设置样式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面我们再回到行星那个例子中。假设只希望选择 moons 属性值为 1 的那些 planet 元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">planet[moons="1"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">上面的代码会把以下标记中的第二个元素变成红色，但第一个和第三个元素不受影响：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;planet&gt;Venus&lt;/planet&gt; &lt;planet <span style="color: #ff0000; ">moons="1"</span>&gt;Earth&lt;/planet&gt; &lt;planet moons="2"&gt;Mars&lt;/planet&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/css/planetml_attselector_val.xml" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">查看效果</a></p><h3>属性与属性值必须完全匹配</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请注意，这种格式要求必须与属性值完全匹配。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果属性值包含用空格分隔的值列表，匹配就可能出问题。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请考虑一下的标记片段：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;p <span style="color: #ff0000; ">class="important warning"</span>&gt;This paragraph is a very important warning.&lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果写成 p[class="important"]，那么这个规则不能匹配示例标记。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">要根据具体属性值来选择该元素，必须这样写：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p[class="important warning"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_value_3" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>根据部分属性值选择</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果需要根据属性值中的词列表的某个词进行选择，则需要使用波浪号（~）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设您想选择 class 属性中包含 important 的元素，可以用下面这个选择器做到这一点：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p[class~="important"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_valuelist_space_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果忽略了波浪号，则说明需要完成完全值匹配。</p><h3>部分值属性选择器与点号类名记法的区别</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">该选择器等价于我们在类选择器中讨论过的点号类名记法。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">也就是说，p.important 和 p["important"] 应用到 HTML 文档时是等价的。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">那么，为什么还要有 "~=" 属性选择器呢？因为它能用于任何属性，而不只是 class。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，可以有一个包含大量图像的文档，其中只有一部分是图片。对此，可以使用一个基于 title 文档的部分属性选择器，只选择这些图片：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">img[title~="Figure"] {border: 1px solid gray;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个规则会选择 title 文本包含 "Figure" 的所有图像。没有 title 属性或者 title 属性中不包含 "Figure" 的图像都不会匹配。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_valuelist_space_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>子串匹配属性选择器</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面为您介绍一个更高级的选择器模块，它是 CSS2 完成之后发布的，其中包含了更多的部分值属性选择器。按照规范的说法，应该称之为&#8220;子串匹配属性选择器&#8221;。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">很多现代浏览器都支持这些选择器，包括 IE7。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下表是对这些选择器的简单总结：</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">类型</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">[abd^="def"]</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">选择 abc 属性值以 "def" 开头的所有元素</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">[abd$="def"]</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">选择 abc 属性值以 "def" 结尾的所有元素</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">[abd*="def"]</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">选择 abc 属性值中包含子串 "def" 的所有元素</td></tr></tbody></table><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">可以想到，这些选择有很多用途。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">举例来说，如果希望对指向 W3School 的所有链接应用样式，不必为所有这些链接指定 class，再根据这个类编写样式，而只需编写以下规则：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">a[href*="w3school.com.cn"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_substring_matching" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>任何属性都可以使用这些选择器。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>特定属性选择类型</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">最后为您介绍特定属性选择器。请看下面的例子：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">*[lang|="en"] {color: red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">上面这个规则会选择 lang 属性等于 en 或以 en- 开头的所有元素。因此，以下示例标记中的前三个元素将被选中，而不会选择后两个元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;p lang="<span style="color: #ff0000; ">en</span>"&gt;Hello!&lt;/p&gt; &lt;p lang="<span style="color: #ff0000; ">en-</span>us"&gt;Greetings!&lt;/p&gt; &lt;p lang="<span style="color: #ff0000; ">en-</span>au"&gt;G'day!&lt;/p&gt; &lt;p lang="fr"&gt;Bonjour!&lt;/p&gt; &lt;p lang="cy-en"&gt;Jrooana!&lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_valuelist_hyphen_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">一般来说，[att|="val"] 可以用于任何属性及其值。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设一个 HTML 文档中有一系列图片，其中每个图片的文件名都形如&nbsp;<em>figure-1.jpg</em>&nbsp;和&nbsp;<em>figure-2.jpg</em>。就可以使用以下选择器匹配所有这些图像：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">img[src|="figure"] {border: 1px solid gray;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_attribute_valuelist_hyphen_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">当然，这种属性选择器最常见的用途还是匹配语言值。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147512.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:17 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147512.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS ID 选择器详解</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147511.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:16:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147511.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147511.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147511.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147511.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147511.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">ID 选择器允许以一种独立于文档元素的方式来指定样式。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS ID 选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在某些方面，ID 选择器类似于类选择器，不过也有一些重要差别。</p><h3>语法</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">首先，ID 选择器前面有一个 # 号 - 也称为棋盘号或井号。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请看下面的规则：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">*#intro {font-weight:bold;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">与类选择器一样，ID 选择器中可以忽略通配选择器。前面的例子也可以写作：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">#intro {font-weight:bold;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个选择器的效果将是一样的。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">第二个区别是 ID 选择器不引用 class 属性的值，毫无疑问，它要引用 id 属性中的值。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">以下是一个实际 ID 选择器的例子：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;p <span style="color: #ff0000; ">id="intro"</span>&gt;This is a paragraph of introduction.&lt;/p&gt;</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_id" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>类选择器还是 ID 选择器？</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在类选择器这一章中我们曾讲解过，可以为任意多个元素指定类。前一章中类名 important 被应用到 p 和 h1 元素，而且它还可以应用到更多元素。</p><h3>区别 1：只能在文档中使用一次</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">与类不同，在一个 HTML 文档中，ID 选择器会使用一次，而且仅一次。</p><h3>区别 2：不能使用 ID 词列表</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">不用于类选择器，ID 选择器不能结合使用，因为 ID 属性不允许有以空格分隔的词列表。</p><h3>区别 3：ID 能包含更多含义</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">类似于类，可以独立于元素来选择 ID。有些情况下，您知道文档中会出现某个特定 ID 值，但是并不知道它会出现在哪个元素上，所以您想声明独立的 ID 选择器。例如，您可能知道在一个给定的文档中会有一个 ID 值为 mostImportant 的元素。您不知道这个最重要的东西是一个段落、一个短语、一个列表项还是一个小节标题。您只知道每个文档都会有这么一个最重要的内容，它可能在任何元素中，而且只能出现一个。在这种情况下，可以编写如下规则：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">#mostImportant {color:red; background:yellow;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个规则会与以下各个元素匹配（这些元素不能在同一个文档中同时出现，因为它们都有相同的 ID 值）：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;h1 <span style="color: #ff0000; ">id="mostImportant"</span>&gt;This is important!&lt;/h1&gt; &lt;em <span style="color: #ff0000; ">id="mostImportant"</span>&gt;This is important!&lt;/em&gt; &lt;ul <span style="color: #ff0000; ">id="mostImportant"</span>&gt;This is important!&lt;/ul&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">亲自试一试：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_id_h1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">为 id 为 mostImportant 的 h1 元素设定样式</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_id_em" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">为 id 为 mostImportant 的 em 元素设定样式</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_id_ul" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">为 id 为 mostImportant 的 ul 元素设定样式</a></li></ul></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>区分大小写</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请注意，类选择器和 ID 选择器可能是区分大小写的。这取决于文档的语言。HTML 和 XHTML 将类和 ID 值定义为区分大小写，所以类和 ID 值的大小写必须与文档中的相应值匹配。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">因此，对于以下的 CSS 和 HTML，元素不会变成粗体：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">#intro {font-weight:bold;}  &lt;p <span style="color: #ff0000; ">id="Intro"</span>&gt;This is a paragraph of introduction.&lt;/p&gt;</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">由于字母 i 的大小写不同，所以选择器不会匹配上面的元素。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147511.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:16 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147511.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 类选择器详解</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147510.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:15:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147510.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147510.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147510.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147510.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147510.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">类选择器允许以一种独立于文档元素的方式来指定样式。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 类选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">类选择器允许以一种独立于文档元素的方式来指定样式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">该选择器可以单独使用，也可以与其他元素结合使用。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>只有适当地标记文档后，才能使用这些选择器，所以使用这两种选择器通常需要先做一些构想和计划。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">要应用样式而不考虑具体设计的元素，最常用的方法就是使用类选择器。</p><h3>修改 HTML 代码</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在使用类选择器之前，需要修改具体的文档标记，以便类选择器正常工作。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">为了将类选择器的样式与元素关联，必须将 class 指定为一个适当的值。请看下面的 HTML 代码：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;h1 <span style="color: #ff0000; ">class="important"</span>&gt; This heading is very important. &lt;/h1&gt;  &lt;p <span style="color: #ff0000; ">class="important"</span>&gt; This paragraph is very important. &lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在上面的代码中，两个元素的 class 都指定为 important：第一个标题（ h1 元素），第二个段落（p 元素）。</p><h3>语法</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">然后我们使用以下语法向这些归类的元素应用样式，即类名前有一个点号（.），然后结合通配选择器：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">*.important {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果您只想选择所有类名相同的元素，可以在类选择器中忽略通配选择器，这没有任何不好的影响：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">.important {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_class_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><h3>结合元素选择器</h3><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">类选择器可以结合元素选择器来使用。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，您可能希望只有段落显示为红色文本：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p.important {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">选择器现在会匹配 class 属性包含 important 的所有 p 元素，但是其他任何类型的元素都不匹配，不论是否有此 class 属性。选择器 p.important 解释为：&#8220;其 class 属性值为 important 的所有段落&#8221;。 因为 h1 元素不是段落，这个规则的选择器与之不匹配，因此 h1 元素不会变成红色文本。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果你确实希望为 h1 元素指定不同的样式，可以使用选择器 h1.important：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p.important {color:red;} h1.important {color:blue;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_class_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 多类选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在上一节中，我们处理了 class 值中包含一个词的情况。在 HTML 中，一个 class 值中可能包含一个词列表，各个词之间用空格分隔。例如，如果希望将一个特定的元素同时标记为重要（important）和警告（warning），就可以写作：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;p <span style="color: #ff0000; ">class="important warning"</span>&gt; This paragraph is a very important warning. &lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这两个词的顺序无关紧要，写成 warning important 也可以。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">我们假设 class 为 important 的所有元素都是粗体，而 class 为 warning 的所有元素为斜体，class 中同时包含 important 和 warning 的所有元素还有一个银色的背景 。就可以写作：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">.important {font-weight:bold;} .warning {font-weight:italic;} <code style="font-family: 'Courier New', monospace; color: #0000ff; ">.important.warning {background:silver;}</code> </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_class_multiple" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">通过把两个类选择器链接在一起，仅可以选择<em style="font-style: normal; font-weight: bold; ">同时包含这些类名</em>的元素（类名的顺序不限）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果一个多类选择器包含类名列表中没有的一个类名，匹配就会失败。请看下面的规则：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">.important.urgent {background:silver;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">不出所料，这个选择器将只匹配 class 属性中包含词 important 和 urgent 的 p 元素。因此，如果一个 p 元素的 class 属性中只有词 important 和 warning，将不能匹配。不过，它能匹配以下元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;p <span style="color: #ff0000; ">class="important urgent warning"</span>&gt; This paragraph is a very important and urgent warning. &lt;/p&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_class_multiple_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #dd0000; ">重要事项：</span>在 IE7 之前的版本中，不同平台的 Internet Explorer 都不能正确地处理多类选择器。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147510.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:15 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147510.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 分组</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147509.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:14:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147509.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147509.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147509.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147509.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147509.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>选择器分组</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设希望 h2 元素和段落都有灰色。为达到这个目的，最容易的做法是使用以下声明：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h2, p {color:gray;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">将 h2 和 p 选择器放在规则左边，然后用逗号分隔，就定义了一个规则。其右边的样式（color:gray;）将应用到这两个选择器所引用的元素。逗号告诉浏览器，规则中包含两个不同的选择器。如果没有这个逗号，那么规则的含义将完全不同。参见后代选择器。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">可以将任意多个选择器分组在一起，对此没有任何限制。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，如果您想把很多元素显示为灰色，可以使用类似如下的规则：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">body, h2, p, table, th, td, pre, strong, em {color:gray;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>通过分组，创作者可以将某些类型的样式&#8220;压缩&#8221;在一起，这样就可以得到更简洁的样式表。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">以下的两组规则能得到同样的结果，不过可以很清楚地看出哪一个写起来更容易：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; "><span style="color: #999999; ">/* no grouping */</span> h1 {color:blue;} h2 {color:blue;} h3 {color:blue;} h4 {color:blue;} h5 {color:blue;} h6 {color:blue;}  <span style="color: #999999; ">/* grouping */</span> h1, h2, h3, h4, h5, h6 {color:blue;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_selector" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">分组提供了一些有意思的选择。例如，下例中的所有规则分组都是等价的，每个组只是展示了对选择器和声明分组的不同方法：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; "><span style="color: #999999; ">/* group 1 */</span> h1 {color:silver; background:white;} h2 {color:silver; background:gray;} h3 {color:white; background:gray;} h4 {color:silver; background:white;} b {color:gray; background:white;}  <span style="color: #999999; ">/* group 2 */</span> h1, h2, h4 {color:silver;} h2, h3 {background:gray;} h1, h4, b {background:white;} h3 {color:white;} b {color:gray;}  <span style="color: #999999; ">/* group 3 */</span> h1, h4 {color:silver; background:white;} h2 {color:silver;} h3 {color:white;} h2, h3 {background:gray;} b {color:gray; background:white;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">亲自试一试：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_selector_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">group 1</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_selector_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">group 2</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_selector_3" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">group 3</a></li></ul><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请注意，group 3 中使用了&#8220;声明分组&#8221;。稍后我们会为您介绍&#8220;声明分组&#8221;。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>通配符选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS2 引入了一种新的简单选择器 - 通配选择器（universal selector），显示为一个星号（*）。该选择器可以与任何元素匹配，就像是一个通配符。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，下面的规则可以使文档中的每个元素都为红色：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">* {color:red;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_selector_universal" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这个声明等价于列出了文档中所有元素的一个分组选择器。利用通配选择器，只需敲一次键（仅一个星号）就能使文档中所有元素的 color 属性值指定为 red。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>声明分组</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">我们既可以对选择器进行分组，也可以对声明分组。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设您希望所有 h1 元素都有红色背景，并使用 28 像素高的 Verdana 字体显示为蓝色文本，可以写以下样式：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {font: 28px Verdana;} h1 {color: blue;} h1 {background: red;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">但是上面这种做法的效率并不高。尤其是当我们为一个有多个样式的元素创建这样一个列表时会很麻烦。相反，我们可以将声明分组在一起：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {font: 28px Verdana; color: white; background: black;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这与前面的 3 行样式表的效果完全相同。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">注意，对声明分组，一定要在各个声明的最后使用分号，这很重要。浏览器会忽略样式表中的空白符。只要加了分号，就可以毫无顾忌地采用以下格式建立样式：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {   font: 28px Verdana;   color: blue;   background: red;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_declaration" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">怎么样，上面这种写法的可读性是不是更强。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">不过，如果忽略了第二个分号，用户代理就会把这个样式表解释如下：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {   font: 28px Verdana;   <code style="font-family: 'Courier New', monospace; color: #0000ff; ">color: blue background: red;</code>   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping_declaration_error" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">因为 background 对 color 来说不是一个合法值，而且由于只能为 color 指定一个关键字，所以用户代理会完全忽略这个 color 声明（包括 background: black 部分）。这样 h1 标题只会显示为蓝色，而没有红色背景，不过更有可能根本得不到蓝色的 h1。相反，这些标题只会显示为默认颜色（通常是黑色），而且根本没有背景色。font: 28px Verdana 声明仍能正常发挥作用，因为它确实正确地以一个分号结尾。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">与选择器分组一样，声明分组也是一种便利的方法，可以缩短样式表，使之更清晰，也更易维护。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>在规则的最后一个声明后也加上分号是一个好习惯。在向规则增加另一个声明时，就不必担心忘记再插入一个分号。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>结合选择器和声明的分组</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">我们可以在一个规则中结合选择器分组和声明分组，就可以使用很少的语句定义相对复杂的样式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的规则为所有标题指定了一种复杂的样式：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1, h2, h3, h4, h5, h6 {   color:gray;   background: white;   padding: 10px;   border: 1px solid black;   font-family: Verdana;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_grouping" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">上面这条规则将所有标题的样式定义为带有白色背景的灰色文本，其内边距是 10 像素，并带有 1 像素的实心边框，文本字体是 Verdana。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147509.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:14 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147509.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 元素选择器</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147508.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:14:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147508.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147508.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147508.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147508.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147508.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 元素选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">最常见的 CSS 选择器是元素选择器。换句话说，文档的元素就是最基本的选择器。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果设置 HTML 的样式，选择器通常将是某个 HTML 元素，比如 p、h1、em、a，甚至可以是 html 本身：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">html {color:black;} h1 {color:blue;} h2 {color:silver;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_type_1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">可以将某个样式从一个元素切换到另一个元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设您决定将上面的段落文本（而不是 h1 元素）设置为灰色。只需要把 h1 选择器该为 p：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">html {color:black;} <code style="font-family: 'Courier New', monospace; color: #0000ff; ">p {color:gray;}</code> h2 {color:silver;} </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_selector_type_2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>类型选择器</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在 W3C 标准中，元素选择器又称为类型选择器（type selector）。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">&#8220;类型选择器匹配文档语言元素类型的名称。类型选择器匹配文档树中该元素类型的每一个实例。&#8221;</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的规则匹配文档树中所有 h1 元素：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {font-family: sans-serif;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">因此，我们也可以为 XML 文档中的元素设置样式：</p><h3>XML 文档：</h3><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;?xml-stylesheet type="text/css" href="note.css"?&gt;</code> &lt;note&gt; &lt;to&gt;George&lt;/to&gt; &lt;from&gt;John&lt;/from&gt; &lt;heading&gt;Reminder&lt;/heading&gt; &lt;body&gt;Don't forget the meeting!&lt;/body&gt; &lt;/note&gt; </pre><h3>CSS 文档：</h3><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">note   {   font-family:Verdana, Arial;   margin-left:30px;   }  to   {   font-size:28px;   display: block;   }  from   {   font-size:28px;   display: block;   }  heading   {   color: red;   font-size:60px;   display: block;   }  body   {   color: blue;   font-size:35px;   display: block;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/example/csse/note_css.xml" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">查看效果</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">通过上面的例子，您可以看到，CSS 元素选择器（类型选择器）可以设置 XML 文档中元素的样式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果您需要更多关于为 XML 文档添加样式的知识，请访问 w3school 的&nbsp;<a href="http://www.w3school.com.cn/xml/index.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">XML 教程</a>。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:14 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147508.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 浮动</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147507.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:13:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147507.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147507.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147507.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147507.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147507.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">浮动的框可以向左或向右移动，直到它的外边缘碰到包含框或另一个浮动框的边框为止。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">由于浮动框不在文档的普通流中，所以文档的普通流中的块框表现得就像浮动框不存在一样。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 浮动</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请看下图，当把框 1 向右浮动时，它脱离文档流并且向右移动，直到它的右边缘碰到包含框的右边缘：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_floating_right_example.gif" alt="CSS 浮动实例 - 向右浮动的元素" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">再请看下图，当框 1 向左浮动时，它脱离文档流并且向左移动，直到它的左边缘碰到包含框的左边缘。因为它不再处于文档流中，所以它不占据空间，实际上覆盖住了框 2，使框 2 从视图中消失。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果把所有三个框都向左移动，那么框 1 向左浮动直到碰到包含框，另外两个框向左浮动直到碰到前一个浮动框。</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_floating_left_example.gif" alt="CSS 浮动实例 - 向左浮动的元素" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如下图所示，如果包含框太窄，无法容纳水平排列的三个浮动元素，那么其它浮动块向下移动，直到有足够的空间。如果浮动元素的高度不同，那么当它们向下移动时可能被其它浮动元素&#8220;卡住&#8221;：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_floating_left_example_2.gif" alt="CSS 浮动实例 2 - 向左浮动的元素 " style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS float 属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在 CSS 中，我们通过 float 属性实现元素的浮动。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如需更多有关 float 属性的知识，请访问参考手册：<a href="http://www.w3school.com.cn/css/pr_class_float.asp" title="CSS float 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">CSS float 属性</a>。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>行框和清理</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">浮动框旁边的行框被缩短，从而给浮动框留出空间，行框围绕浮动框。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">因此，创建浮动框可以使文本围绕图像：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_floating_linebox.gif" alt="行框围绕浮动框" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">要想阻止行框围绕浮动框，需要对该框应用&nbsp;<a href="http://www.w3school.com.cn/css/pr_class_clear.asp" title="CSS clear 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">clear 属性</a>。clear 属性的值可以是 left、right、both 或 none，它表示框的哪些边不应该挨着浮动框。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">为了实现这种效果，在被清理的元素的<em style="font-style: normal; font-weight: bold; ">上外边距</em>上添加足够的空间，使元素的顶边缘垂直下降到浮动框下面：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_floating_clear.gif" alt="clear 属性实例 - 对行框应用 clear" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这是一个有用的工具，它让周围的元素为浮动元素留出空间。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">让我们更详细地看看浮动和清理。假设希望让一个图片浮动到文本块的左边，并且希望这幅图片和文本包含在另一个具有背景颜色和边框的元素中。您可能编写下面的代码：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">.news {   background-color: gray;   border: solid 1px black;   }  .news img {   float: left;   }  .news p {   float: right;   }  &lt;div class="news"&gt; &lt;img src="news-pic.jpg" /&gt; &lt;p&gt;some text&lt;/p&gt; &lt;/div&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这种情况下，出现了一个问题。因为浮动元素脱离了文档流，所以包围图片和文本的 div 不占据空间。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如何让包围元素在视觉上包围浮动元素呢？需要在这个元素中的某个地方应用 clear：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_floating_clear_div.gif" alt="clear 属性实例 - 对空元素应用清理" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">不幸的是出现了一个新的问题，由于没有现有的元素可以应用清理，所以我们只能添加一个空元素并且清理它。</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">.news {   background-color: gray;   border: solid 1px black;   }  .news img {   float: left;   }  .news p {   float: right;   }  <code style="font-family: 'Courier New', monospace; color: #0000ff; ">.clear {   clear: both;   }</code>  &lt;div class="news"&gt; &lt;img src="news-pic.jpg" /&gt; &lt;p&gt;some text&lt;/p&gt; <code style="font-family: 'Courier New', monospace; color: #0000ff; ">&lt;div class="clear"&gt;&lt;/div&gt;</code> &lt;/div&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这样可以实现我们希望的效果，但是需要添加多余的代码。常常有元素可以应用 clear，但是有时候不得不为了进行布局而添加无意义的标记。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">不过我们还有另一种办法，那就是对容器 div 进行浮动：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">.news {   background-color: gray;   border: solid 1px black;   <code style="font-family: 'Courier New', monospace; color: #0000ff; ">float: left;</code>   }  .news img {   float: left;   }  .news p {   float: right;   }  &lt;div class="news"&gt; &lt;img src="news-pic.jpg" /&gt; &lt;p&gt;some text&lt;/p&gt; &lt;/div&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这样会得到我们希望的效果。不幸的是，下一个元素会受到这个浮动元素的影响。为了解决这个问题，有些人选择对布局中的所有东西进行浮动，然后使用适当的有意义的元素（常常是站点的页脚）对这些浮动进行清理。这有助于减少或消除不必要的标记。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">事实上，W3School 站点上的所有页面都采用了这种技术，如果您打开我们使用 CSS 文件，您会看到我们对页脚的 div 进行了清理，而页脚上面的三个 div 都向左浮动。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS clear 属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">我们刚才详细讨论了 CSS 清理的工作原理和 clear 属性应用方法。如果您希望学习更多有关 clear 属性的知识，请访问参考手册：<a href="http://www.w3school.com.cn/css/pr_class_clear.asp" title="CSS clear 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">CSS clear 属性</a>。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>浮动和清理 实例</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">float 属性的简单应用</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使图像浮动于一个段落的右侧。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">将带有边框和边界的图像浮动于段落的右侧</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使图像浮动于段落的右侧。向图像添加边框和边界。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float3" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">带标题的图像浮动于右侧</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使带有标题的图像浮动于右侧</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float4" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使段落的首字母浮动于左侧</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使段落的首字母浮动于左侧，并向这个字母添加样式。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float5" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">创建水平菜单</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使用具有一栏超链接的浮动来创建水平菜单。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_float6" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">创建无表格的首页</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">使用浮动来创建拥有页眉、页脚、左侧目录和主体内容的首页。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_class-clear" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">清除元素的侧面</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用清除元素侧面的浮动元素。</dd></dl></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147507.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:13 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147507.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 绝对定位</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147505.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:12:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147505.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147505.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147505.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147505.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147505.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">设置为绝对定位的元素框从文档流完全删除，并相对于其包含块定位，包含块可能是文档中的另一个元素或者是初始包含块。元素原先在正常文档流中所占的空间会关闭，就好像该元素原来不存在一样。元素定位后生成一个块级框，而不论原来它在正常流中生成何种类型的框。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 绝对定位</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">绝对定位使元素的位置与文档流无关，因此不占据空间。这一点与相对定位不同，相对定位实际上被看作普通流定位模型的一部分，因为元素的位置相对于它在普通流中的位置。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">普通流中其它元素的布局就像绝对定位的元素不存在一样：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">#box_relative {   position: absolute;   left: 30px;   top: 20px; } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如下图所示：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_absolute_example.gif" alt="CSS 绝对定位实例" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">绝对定位的元素的位置相对于<em style="font-style: normal; font-weight: bold; ">最近的已定位祖先元素</em>，如果元素没有已定位的祖先元素，那么它的位置相对于<em style="font-style: normal; font-weight: bold; ">最初的包含块</em>。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">对于定位的主要问题是要记住每种定位的意义。所以，现在让我们复习一下学过的知识吧：相对定位是&#8220;相对于&#8221;元素在文档中的初始位置，而绝对定位是&#8220;相对于&#8221;最近的已定位祖先元素，如果不存在已定位的祖先元素，那么&#8220;相对于&#8221;最初的包含块。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>根据用户代理的不同，最初的包含块可能是画布或 HTML 元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>因为绝对定位的框与文档流无关，所以它们可以覆盖页面上的其它元素。可以通过设置&nbsp;<a href="http://www.w3school.com.cn/css/pr_pos_z-index.asp" title="CSS z-index 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">z-index 属性</a>来控制这些框的堆放次序。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 绝对定位实例</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_absolute" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：绝对定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用绝对值来对元素进行定位。</dd></dl></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147505.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:12 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147505.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 相对定位</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147504.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:12:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147504.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147504.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147504.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147504.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147504.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">设置为相对定位的元素框会偏移某个距离。元素仍然保持其未定位前的形状，它原本所占的空间仍保留。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 相对定位</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">相对定位是一个非常容易掌握的概念。如果对一个元素进行相对定位，它将出现在它所在的位置上。然后，可以通过设置垂直或水平位置，让这个元素&#8220;相对于&#8221;它的起点进行移动。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果将 top 设置为 20px，那么框将在原位置顶部下面 20 像素的地方。如果 left 设置为 30 像素，那么会在元素左边创建 30 像素的空间，也就是将元素向右移动。</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">#box_relative {   position: relative;   left: 30px;   top: 20px; } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如下图所示：</p><img src="http://www.w3school.com.cn/i/ct_css_positioning_relative_example.gif" alt="CSS 相对定位实例" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">注意，在使用相对定位时，无论是否进行移动，元素仍然占据原来的空间。因此，移动元素会导致它覆盖其它框。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 相对定位实例</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_relative" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：相对定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何相对于一个元素的正常位置来对其定位。</dd></dl></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147504.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:12 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 定位 (Positioning)</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147503.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:11:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147503.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147503.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147503.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147503.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147503.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 定位 (Positioning) 属性允许你对元素进行定位。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 定位和浮动</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 为定位和浮动提供了一些属性，利用这些属性，可以建立列式布局，将布局的一部分与另一部分重叠，还可以完成多年来通常需要使用多个表格才能完成的任务。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">定位的基本思想很简单，它允许你定义元素框相对于其正常位置应该出现的位置，或者相对于父元素、另一个元素甚至浏览器窗口本身的位置。显然，这个功能非常强大，也很让人吃惊。要知道，用户代理对 CSS2 中定位的支持远胜于对其它方面的支持，对此不应感到奇怪。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">另一方面，CSS1 中首次提出了浮动，它以 Netscape 在 Web 发展初期增加的一个功能为基础。浮动不完全是定位，不过，它当然也不是正常流布局。我们会在后面的章节中明确浮动的含义。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>一切皆为框</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">div、h1 或 p 元素常常被称为块级元素。这意味着这些元素显示为<em style="font-style: normal; font-weight: bold; ">一块内容</em>，即&#8220;块框&#8221;。与之相反，span 和 strong 等元素称为&#8220;行内元素&#8221;，这是因为它们的内容显示在行中，即&#8220;行内框&#8221;。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您可以使用&nbsp;<a href="http://www.w3school.com.cn/css/pr_class_display.asp" title="CSS display 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">display 属性</a>改变生成的框的类型。这意味着，通过将 display 属性设置为 block，可以让行内元素（比如 &lt;a&gt; 元素）表现得像块级元素一样。还可以通过把 display 设置为 none，让生成的元素根本没有框。这样的话，该框及其所有内容就不再显示，不占用文档中的空间。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">但是在一种情况下，即使没有进行显式定义，也会创建块级元素。这种情况发生在把一些文本添加到一个块级元素（比如 div）的开头。即使没有把这些文本定义为段落，它也会被当作段落对待：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;div&gt; some text &lt;p&gt;Some more text.&lt;/p&gt; &lt;/div&gt; </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在这种情况下，这个框称为无名块框，因为它不与专门定义的元素相关联。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">块级元素的文本行也会发生类似的情况。假设有一个包含三行文本的段落。每行文本形成一个无名框。无法直接对无名块或行框应用样式，因为没有可以应用样式的地方（注意，行框和行内框是两个概念）。但是，这有助于理解在屏幕上看到的所有东西都形成某种框。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 定位机制</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 有三种基本的定位机制：普通流、浮动和绝对定位。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">除非专门指定，否则所有框都在普通流中定位。也就是说，普通流中的元素的位置由元素在 (X)HTML 中的位置决定。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">块级框从上到下一个接一个地排列，框之间的垂直距离是由框的垂直外边距计算出来。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">行内框在一行中水平布置。可以使用水平内边距、边框和外边距调整它们的间距。但是，垂直内边距、边框和外边距不影响行内框的高度。由一行形成的水平框称为<em style="font-style: normal; font-weight: bold; ">行框（Line Box）</em>，行框的高度总是足以容纳它包含的所有行内框。不过，设置行高可以增加这个框的高度。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在下面的章节，我们会为您详细讲解相对定位、绝对定位和浮动。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS position 属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">通过使用&nbsp;<a href="http://www.w3school.com.cn/css/pr_class_position.asp" title="CSS position 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">position 属性</a>，我们可以选择 4 种不同类型的定位，这会影响元素框生成的方式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">position 属性值的含义：</p><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; font-weight: bold; color: #0479a7; ">static</dt><dd style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; line-height: 18px; ">元素框正常生成。块级元素生成一个矩形框，作为文档流的一部分，行内元素则会创建一个或多个行框，置于其父元素中。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; font-weight: bold; color: #0479a7; ">relative</dt><dd style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; line-height: 18px; ">元素框偏移某个距离。元素仍保持其未定位前的形状，它原本所占的空间仍保留。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; font-weight: bold; color: #0479a7; ">absolute</dt><dd style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; line-height: 18px; ">元素框从文档流完全删除，并相对于其包含块定位。包含块可能是文档中的另一个元素或者是初始包含块。元素原先在正常文档流中所占的空间会关闭，就好像元素原来不存在一样。元素定位后生成一个块级框，而不论原来它在正常流中生成何种类型的框。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; font-weight: bold; color: #0479a7; ">fixed</dt><dd style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; line-height: 18px; ">元素框的表现类似于将 position 设置为 absolute，不过其包含块是视窗本身。</dd></dl><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>相对定位实际上被看作普通流定位模型的一部分，因为元素的位置相对于它在普通流中的位置。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>实例</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_relative" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：相对定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何相对于一个元素的正常位置来对其定位。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_absolute" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：绝对定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用绝对值来对元素进行定位。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_fixed" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">定位：固定定位</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何相对于浏览器窗口来对元素进行定位。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_top" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用固定值设置图像的上边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用固定值设置图像的上边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_top_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比设置图像的上边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值设置图像的上边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_bottom" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用像素值设置图像的底部边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用像素值设置图像的底部边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_bottom_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比设置图像的底部边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值设置图像的底部边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_left" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用固定值设置图像的左边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用固定值设置图像的左边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_left_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比设置图像的左边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值设置图像的左边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_right" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用固定值设置图像的右边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用固定值设置图像的右边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_position_right_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">使用百分比设置图像的右边缘</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值设置图像的右边缘。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_overflow" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">如何使用滚动条来显示元素内溢出的内容</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示当元素内容太大而超出规定区域时，如何设置溢出属性来规定相应的动作。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_pos_overflow_hidden" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">如何隐藏溢出元素中溢出的内容</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示在元素中的内容太大以至于无法适应指定的区域时，如何设置 overflow 属性来隐藏其内容。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_pos_overflow_auto" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">如何设置浏览器来自动地处理溢出</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置浏览器来自动地处理溢出。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_clip" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置元素的形状</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置元素的形状。此元素被剪裁到这个形状内，并显示出来。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_vertical-align" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">垂直排列图象</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何在文本中垂直排列图象。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_zindex2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">Z-index</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Z-index可被用于将在一个元素放置于另一元素之后。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_zindex1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">Z-index</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">上面的例子中的元素已经更改了Z-index。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 定位属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS 定位属性允许你对元素进行定位。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_class_position.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">position</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">把元素放置到一个静态的、相对的、绝对的、或固定的位置中。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_top.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">top</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_right.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">right</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">定义了定位元素右外边距边界与其包含块右边界之间的偏移。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_bottom.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">bottom</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">定义了定位元素下外边距边界与其包含块下边界之间的偏移。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_left.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">left</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">定义了定位元素左外边距边界与其包含块左边界之间的偏移。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_overflow.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">overflow</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置当元素的内容溢出其区域时发生的事情。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_clip.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">clip</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的形状。元素被剪入这个形状之中，然后显示出来。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_vertical-align.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">vertical-align</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的垂直对齐方式。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_pos_z-index.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">z-index</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的堆叠顺序。</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147503.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:11 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147503.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 外边距合并</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147502.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:09:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147502.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147502.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147502.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147502.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147502.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">外边距合并指的是，当两个垂直外边距相遇时，它们将形成一个外边距。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>外边距合并</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">外边距合并（叠加）是一个相当简单的概念。但是，在实践中对网页进行布局时，它会造成许多混淆。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">简单地说，外边距合并指的是，当两个垂直外边距相遇时，它们将形成一个外边距。合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">当一个元素出现在另一个元素上面时，第一个元素的下外边距与第二个元素的上外边距会发生合并。请看下图：</p><img src="http://www.w3school.com.cn/i/ct_css_margin_collapsing_example_1.gif" alt="CSS 外边距合并实例 1" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin_collapsing1" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">当一个元素包含在另一个元素中时（假设没有内边距或边框把外边距分隔开），它们的上和/或下外边距也会发生合并。请看下图：</p><img src="http://www.w3school.com.cn/i/ct_css_margin_collapsing_example_2.gif" alt="CSS 外边距合并实例 2" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin_collapsing2" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">尽管看上去有些奇怪，但是外边距甚至可以与自身发生合并。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设有一个空元素，它有外边距，但是没有边框或填充。在这种情况下，上外边距与下外边距就碰到了一起，它们会发生合并：</p><img src="http://www.w3school.com.cn/i/ct_css_margin_collapsing_example_3.gif" alt="CSS 外边距合并实例 3" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果这个外边距遇到另一个元素的外边距，它还会发生合并：</p><img src="http://www.w3school.com.cn/i/ct_css_margin_collapsing_example_4.gif" alt="CSS 外边距合并实例 4" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这就是一系列的段落元素占用空间非常小的原因，因为它们的所有外边距都合并到一起，形成了一个小的外边距。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">外边距合并初看上去可能有点奇怪，但是实际上，它是有意义的。以由几个段落组成的典型文本页面为例。第一个段落上面的空间等于段落的上外边距。如果没有外边距合并，后续所有段落之间的外边距都将是相邻上外边距和下外边距的和。这意味着段落之间的空间是页面顶部的两倍。如果发生外边距合并，段落之间的上外边距和下外边距就合并在一起，这样各处的距离就一致了。</p><img src="http://www.w3school.com.cn/i/ct_css_margin_collapsing.gif" alt="CSS 外边距合并的实际意义" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; ">注释：</span>只有普通文档流中块框的垂直外边距才会发生外边距合并。行内框、浮动框或绝对定位之间的外边距不会合并。</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:09 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 外边距</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147501.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:09:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147501.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147501.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147501.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147501.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147501.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">围绕在元素边框的空白区域是外边距。设置外边距会在元素外创建额外的&#8220;空白&#8221;。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">设置外边距的最简单的方法就是使用 margin 属性，这个属性接受任何长度单位、百分数值甚至负值。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS margin 属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">设置外边距的最简单的方法就是使用&nbsp;<a href="http://www.w3school.com.cn/css/pr_margin.asp" title="CSS margin 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin 属性</a>。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">margin 属性接受任何长度单位，可以是像素、英寸、毫米或 em。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">margin 可以设置为 auto。更常见的做法是为外边距设置长度值。下面的声明在 h1 元素的各个边上设置了 1/4 英寸宽的空白：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {margin : 0.25in;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的例子为 h1 元素的四个边分别定义了不同的外边距，所使用的长度单位是像素 (px)：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {margin : 10px 0px 15px 5px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">与内边距的设置相同，这些值的顺序是从上外边距 (top) 开始围着元素顺时针旋转的：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">margin: top right bottom left</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">另外，还可以为 margin 设置一个百分比数值：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin : 10%;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">百分数是相对于父元素的 width 计算的。上面这个例子为 p 元素设置的外边距是其父元素的 width 的 10%。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">margin 的默认值是 0，所以如果没有为 margin 声明一个值，就不会出现外边距。但是，在实际中，浏览器对许多元素已经提供了预定的样式，外边距也不例外。例如，在支持 CSS 的浏览器中，外边距会在每个段落元素的上面和下面生成&#8220;空行&#8221;。因此，如果没有为 p 元素声明外边距，浏览器可能会自己应用一个外边距。当然，只要你特别作了声明，就会覆盖默认样式。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>值复制</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">还记得吗？我们曾经在前两节中提到过值复制。下面我们为您讲解如何使用值复制。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">有时，我们会输入一些重复的值：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin: 0.5em 1em 0.5em 1em;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">通过值复制，您可以不必重复地键入这对数字。上面的规则与下面的规则是等价的：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin: 0.5em 1em;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这两个值可以取代前面 4 个值。这是如何做到的呢？CSS 定义了一些规则，允许为外边距指定少于 4 个值。规则如下：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; ">如果缺少左外边距的值，则使用右外边距的值。</li><li style="margin-top: 3px; ">如果缺少下外边距的值，则使用上外边距的值。</li><li style="margin-top: 3px; ">如果缺少右外边距的值，则使用上外边距的值。</li></ul><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下图提供了更直观的方法来了解这一点：</p><img src="http://www.w3school.com.cn/i/ct_css_margin_value.gif" alt="CSS 值复制" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">换句话说，如果为外边距指定了 3 个值，则第 4 个值（即左外边距）会从第 2 个值（右外边距）复制得到。如果给定了两个值，第 4 个值会从第 2 个值复制得到，第 3 个值（下外边距）会从第 1 个值（上外边距）复制得到。最后一个情况，如果只给定一个值，那么其他 3 个外边距都由这个值（上外边距）复制得到。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">利用这个简单的机制，您只需指定必要的值，而不必全部都应用 4 个值，例如：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {margin: 0.25em 1em 0.5em;}	<span style="color: #999999; ">/* 等价于 0.25em 1em 0.5em 1em */</span> h2 {margin: 0.5em 1em;}		<span style="color: #999999; ">/* 等价于 0.5em 1em 0.5em 1em */</span> p {margin: 1px;}			<span style="color: #999999; ">/* 等价于 1px 1px 1px 1px */</span> </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这种办法有一个小缺点，您最后肯定会遇到这个问题。假设希望把 p 元素的上外边距和左外边距设置为 20 像素，下外边距和右外边距设置为 30 像素。在这种情况下，必须写作：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin: 20px 30px 30px 20px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">这样才能得到您想要的结果。遗憾的是，在这种情况下，所需值的个数没有办法更少了。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">再来看另外一个例子。如果希望除了左外边距以外所有其他外边距都是 auto（左外边距是 20px）：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin: auto auto auto 20px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">同样的，这样才能得到你想要的效果。问题在于，键入这些 auto 有些麻烦。如果您只是希望控制元素单边上的外边距，请使用单边外边距属性。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>单边外边距属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您可以使用单边外边距属性为元素单边上的外边距设置值。假设您希望把 p 元素的左外边距设置为 20px。不必使用 margin（需要键入很多 auto），而是可以采用以下方法：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin-left: 20px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您可以使用下列任何一个属性来只设置相应上的外边距，而不会直接影响所有其他外边距：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_margin-top.asp" title="CSS margin-top 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-top</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_margin-right.asp" title="CSS margin-right 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-right</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_margin-bottom.asp" title="CSS margin-bottom 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-bottom</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_margin-left.asp" title="CSS margin-left 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-left</a></li></ul><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">一个规则中可以使用多个这种单边属性，例如：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h2 {   margin-top: 20px;   margin-right: 30px;   margin-bottom: 30px;   margin-left: 20px;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">当然，对于这种情况，使用 margin 可能更容易一些：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {margin: 20px 30px 30px 20px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">不论使用单边属性还是使用 margin，得到的结果都一样。一般来说，如果希望为多个边设置外边距，使用 margin 会更容易一些。不过，从文档显示的角度看，实际上使用哪种方法都不重要，所以应该选择对自己来说更容易的一种方法。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>提示和注释</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>Netscape 和 IE 对 body 标签定义的默认边距（margin）值是 8px。而 Opera 不是这样。相反地，Opera 将内部填充（padding）的默认值定义为 8px，因此如果希望对整个网站的边缘部分进行调整，并将之正确显示于 Opera 中，那么必须对 body 的 padding 进行自定义。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 外边距实例：</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin-left" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置文本的左外边距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置文本的左外边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin-right" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置文本的右外边距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置文本的右外边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin-top" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置文本的上外边距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置文本的上外边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin-bottom" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置文本的下外边距</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置文本的下外边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_margin" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">所有的外边距属性在一个声明中。</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何将所有的外边距属性设置于一个声明中。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 外边距属性</h2><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_margin.asp" title="CSS margin 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">简写属性。在一个声明中设置所有外边距属性。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_margin-bottom.asp" title="CSS margin-bottom 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-bottom</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的下外边距。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_margin-left.asp" title="CSS margin-left 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-left</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的左外边距。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_margin-right.asp" title="CSS margin-right 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-right</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的右外边距。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_margin-top.asp" title="CSS margin-top 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">margin-top</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的上外边距。</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147501.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:09 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147501.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 边框</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147500.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:08:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147500.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147500.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147500.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 元素的边框 (border) 是围绕元素内容和内边距的一条或多条线。CSS border 属性允许你规定元素边框的样式、宽度和颜色。CSS 边框在 HTML 中，我们使用表格来创建文本周围的边框，但是通过使用 CSS 边框属性，我们可以创建出效果出色的边框，并且可以应用于任何元素。元素外边距内就是元素的的边框 (border)。元素的边框就是围绕元素内容和内边据的一条或多条线。每个边框有 3 个方...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/05/28/147500.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/147500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:08 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 内边距</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147499.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:04:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147499.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147499.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147499.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147499.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">元素的内边距在边框和内容区之间。控制该区域最简单的属性是 padding 属性。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS padding 属性定义元素边框与元素内容之间的空白区域。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS padding 属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">CSS padding 属性定义元素的内边距。padding 属性接受长度值或百分比值，但不允许使用负值。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如，如果您希望所有 h1 元素的各边都有 10 像素的内边距，只需要这样：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {padding: 10px;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您还可以按照上、右、下、左的顺序分别设置各边的内边距，各边均可以使用不同的单位或百分比值：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {padding: 10px 0.25em 2ex 20%;}</pre></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>单边内边距属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">也通过使用下面四个单独的属性，分别设置上、右、下、左内边距：</p><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_padding-top.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-top</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_padding-right.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-right</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_padding-bottom.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-bottom</a></li><li style="margin-top: 3px; "><a href="http://www.w3school.com.cn/css/pr_padding-left.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-left</a></li></ul><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">您也许已经想到了，下面的规则实现的效果与上面的简写规则是完全相同的：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">h1 {   padding-top: 10px;   padding-right: 0.25em;   padding-bottom: 2ex;   padding-left: 20%;   } </pre></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>内边距的百分比数值</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">前面提到过，可以为元素的内边距设置百分数值。百分数值是相对于其父元素的 width 计算的，这一点与外边距一样。所以，如果父元素的 width 改变，它们也会改变。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面这条规则把段落的内边距设置为父元素 width 的 10%：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">p {padding: 10%;}</pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">例如：如果一个段落的父元素是 div 元素，那么它的内边距要根据 div 的 width 计算。</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">&lt;div style="width: 200px;"&gt; &lt;p&gt;This paragragh is contained within a DIV that has a width of 200 pixels.&lt;/p&gt; &lt;/div&gt;  </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #dd0000; ">注意：</span>上下内边距与左右内边距一致；即上下内边距的百分数会相对于父元素宽度设置，而不是相对于高度。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 内边距实例：</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">所有内边距属性在一个声明中</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示使用简写属性将所有的内边距属性设置于一个声明中，可以有一到四个值。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-bottom" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置下内边距 1</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用厘米值来设置单元格的下内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-bottom_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置下内边距 2</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置单元格的下内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-left" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置左内边距 1</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用厘米值来设置单元格的左内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-left_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置左内边距 2</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置单元格的左内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-right" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置右内边距 1</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用厘米值来设置单元格的右内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-right_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置右内边距 2</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置单元格的右内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-top" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置上内边距 1</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用厘米值来设置单元格的上内边距。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_padding-top_percent" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置上内边距 2</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何使用百分比值来设置单元格的上内边距。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 内边距属性</h2><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_padding.asp" title="CSS padding 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">简写属性。作用是在一个声明中设置元素的所内边距属性。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_padding-bottom.asp" title="CSS padding-bottom 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-bottom</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的下内边距。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_padding-left.asp" title="CSS padding-left 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-left</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的左内边距。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_padding-right.asp" title="CSS padding-right 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-right</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的右内边距。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_padding-top.asp" title="CSS padding-top 属性" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">padding-top</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置元素的上内边距。</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:04 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 框模型概述</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147498.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:03:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147498.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147498.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147498.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147498.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147498.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 框模型 (Box Model) 规定了元素框处理元素内容、<a href="http://www.w3school.com.cn/css/css_padding.asp" title="CSS 内边距" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">内边距</a>、<a href="http://www.w3school.com.cn/css/css_border.asp" title="CSS 边框" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">边框</a>&nbsp;和&nbsp;<a href="http://www.w3school.com.cn/css/css_margin.asp" title="CSS 外边距" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">外边距</a>&nbsp;的方式。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 框模型概述</h2><img src="http://www.w3school.com.cn/i/ct_boxmodel.gif" alt="CSS 框模型" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">元素框的最内部分是实际的内容，直接包围内容的是内边距。内边距呈现了元素的背景。内边距的边缘是边框。边框以外是外边距，外边距默认是透明的，因此不会遮挡其后的任何元素。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>背景应用于由内容和内边距组成的区域。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">内边距、边框和外边距都是可选的，默认值是零。但是，许多元素将由用户代理样式表设置外边距和内边距。可以通过将元素的 margin 和 padding 设置为零来覆盖这些浏览器样式。这可以分别进行，也可以使用通用选择器对所有元素进行设置：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">* {   margin: 0;   padding: 0; } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在 CSS 中，width 和 height 指的是内容区域的宽度和高度。增加内边距、边框和外边距不会影响内容区域的尺寸，但是会增加元素框的总尺寸。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">假设框的每个边上有 10 个像素的外边距和 5 个像素的内边距。如果希望这个元素框达到 100 个像素，就需要将内容的宽度设置为 70 像素，请看下图：</p><img src="http://www.w3school.com.cn/i/ct_css_boxmodel_example.gif" alt="CSS 框模型实例" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; " /><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">#box {   width: 70px;   margin: 10px;   padding: 5px; } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>内边距、边框和外边距可以应用于一个元素的所有边，也可以应用于单独的边。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><span style="font-weight: bold; color: #ff9955; ">提示：</span>外边距可以是负值，而且在很多情况下都要使用负值的外边距。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>浏览器兼容性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">一旦为页面设置了恰当的 DTD，大多数浏览器都会按照上面的图示来呈现内容。然而 IE 5 和 6 的呈现却是不正确的。根据 W3C 的规范，元素内容占据的空间是由 width 属性设置的，而内容周围的 padding 和 border 值是另外计算的。不幸的是，IE5.X 和 6 在怪异模式中使用自己的非标准模型。这些浏览器的 width 属性不是内容的宽度，而是内容、内边距和边框的宽度的总和。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">虽然有方法解决这个问题。但是目前最好的解决方案是回避这个问题。也就是，不要给元素添加具有指定宽度的内边距，而是尝试将内边距或外边距添加到元素的父元素和子元素。</p><h3>术语翻译</h3><ul style="margin-top: 10px; margin-bottom: 0px; "><li style="margin-top: 3px; ">element : 元素。</li><li style="margin-top: 3px; ">padding : 内边距，也有资料将其翻译为填充。</li><li style="margin-top: 3px; ">border : 边框。</li><li style="margin-top: 3px; ">margin : 外边距，也有资料将其翻译为空白或空白边。</li></ul><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">在 w3school，我们把 padding 和 margin 统一地称为内边距和外边距。边框内的空白是内边距，边框外的空白是外边距，很容易记吧：）</p></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147498.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:03 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147498.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 样式笔记 （样式轮廓）</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147497.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:02:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147497.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147497.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147497.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147497.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147497.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">轮廓（outline）是绘制于元素周围的一条线，位于边框边缘的外围，可起到突出元素的作用。</strong></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS outline 属性规定元素轮廓的样式、颜色和宽度。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>轮廓（Outline） 实例：</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_outline" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">在元素周围画线</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示使用outline属性在元素周围画一条线。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_outline-color" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置轮廓的颜色</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置轮廓的颜色。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_outline-style" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置轮廓的样式</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置轮廓的样式。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_outline-width" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置轮廓的宽度</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置轮廓的宽度。</dd></dl></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS 边框属性</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">"CSS" 列中的数字指示哪个 CSS 版本定义了该属性。</p><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 156px; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 363px; ">描述</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; width: 24px; ">CSS</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_outline.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">outline</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">在一个声明中设置所有的轮廓属性。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_outline-color.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">outline-color</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置轮廓的颜色。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_outline-style.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">outline-style</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置轮廓的样式。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_outline-width.asp" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">outline-width</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置轮廓的宽度。</td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">2</td></tr></tbody></table></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147497.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:02 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147497.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[学习笔记] CSS 样式笔记 （样式表格）</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/28/147496.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 28 May 2011 13:01:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/28/147496.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/147496.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/28/147496.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/147496.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/147496.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; "><div id="intro" style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><strong style="font-size: 12px; ">CSS 表格属性可以帮助您极大地改善表格的外观。</strong></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>表格边框</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如需在 CSS 中设置表格边框，请使用 border 属性。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的例子为 table、th 以及 td 设置了蓝色边框：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">table, th, td   {   border: 1px solid blue;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_border" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">请注意，上例中的表格具有双线条边框。这是由于 table、th 以及 td 元素都有独立的边框。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如果需要把表格显示为单线条边框，请使用 border-collapse 属性。</p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>折叠边框</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">border-collapse 属性设置是否将表格边框折叠为单一边框：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">table   {   border-collapse:collapse;   }  table,th, td   {   border: 1px solid black;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_border-collapse" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>表格宽度和高度</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">通过 width 和 height 属性定义表格的宽度和高度。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的例子将表格宽度设置为 100%，同时将 th 元素的高度设置为 50px：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">table   {   width:100%;   }  th   {   height:50px;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_width" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>表格文本对齐</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">text-align 和 vertical-align 属性设置表格中文本的对齐方式。</p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">text-align 属性设置水平对齐方式，比如左对齐、右对齐或者居中：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">td   {   text-align:right;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_align" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">vertical-align 属性设置垂直对齐方式，比如顶部对齐、底部对齐或居中对齐：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">td   {   height:50px;   vertical-align:bottom;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_vertical-align" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>表格内边距</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">如需控制表格中内容与边框的距离，请为 td 和 th 元素设置 padding 属性：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">td   {   padding:15px;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_padding" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>表格颜色</h2><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; ">下面的例子设置边框的颜色，以及 th 元素的文本和背景颜色：</p><pre style="width: 580px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-style: initial; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #778855; border-right-color: #778855; border-bottom-color: #778855; border-left-color: #778855; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font-family: 'Courier New', monospace; font-size: 12px; background-position: initial initial; background-repeat: initial initial; ">table, td, th   {   border:1px solid green;   }  th   {   background-color:green;   color:white;   } </pre><p style="margin-top: 12px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_color" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">亲自试一试</a></p></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>CSS Table 属性</h2><table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; width: 606px; "><tbody><tr><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">属性</th><th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #888888; border-right-color: #888888; border-bottom-color: #888888; border-left-color: #888888; text-align: left; ">描述</th></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_tab_border-collapse.asp" title="" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">border-collapse</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置是否把表格边框合并为单一的边框。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_tab_border-spacing.asp" title="" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">border-spacing</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置分隔单元格边框的距离。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_tab_caption-side.asp" title="" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">caption-side</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置表格标题的位置。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_tab_empty-cells.asp" title="" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">empty-cells</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置是否显示表格中的空单元格。</td></tr><tr><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; "><a href="http://www.w3school.com.cn/css/pr_tab_table-layout.asp" title="" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">table-layout</a></td><td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; ">设置显示单元、行和列的算法。</td></tr></tbody></table></div><div style="width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-right-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-top-width: 1px; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; "><h2>亲自试一试 - 更多实例</h2><dl style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_fancy" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">制作一个漂亮的表格</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何创造一个漂亮的表格。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_empty-cells" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">显示表格中的空单元</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示是否显示表格中的空单元。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_border-spacing" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置表格边框之间的空白</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何设置单元格边框之间的距离。</dd><dt style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; "><a href="http://www.w3school.com.cn/tiy/t.asp?f=csse_table_caption-side" style="text-decoration: underline; color: #900b09; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; ">设置表格标题的位置</a></dt><dd style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">本例演示如何定位表格的标题。</dd></dl></div><div id="bpn" style="height: 21px; width: 607px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 15px; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; border-top-width: 1px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; border-style: initial; border-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-style: initial; border-color: initial; border-top-style: solid; border-top-color: #aaaaaa; border-bottom-style: solid; border-bottom-color: #aaaaaa; background-position: initial initial; background-repeat: initial initial; "><ul style="margin-top: 0px; margin-bottom: 0px; height: 21px; width: 230px; background-image: url(http://www.w3school.com.cn/i/site_bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; position: relative; background-position: 0px -305px; background-repeat: no-repeat no-repeat; "><li style="left: 0px; width: 105px; display: block; height: 21px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; position: absolute; top: 0px; overflow-x: hidden; overflow-y: hidden; "></li></ul></div></span></div><img src ="http://www.cppblog.com/lauer3912/aggbug/147496.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-28 21:01 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/28/147496.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>