<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="css/rss.xslt"?>
<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>完美生活 - HTML/CSS</title><link>http://blog.hnce.net/</link><description>专注于网站技术与网络营销的博客 - </description><generator>RainbowSoft Studio Z-Blog 1.8 Arwen Build 81206</generator><language>zh-CN</language><copyright>Copyright 2005 - 2009, 完美生活(专注于网站技术与网络营销的博客). Some Rights Reserved. </copyright><pubDate>Fri, 10 Sep 2010 20:29:40 +0800</pubDate><item><title>透明Flash效果在Firefox中无法达到效果的解决办法</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/flash-transparent-in-Firefox-not-dispaly-solution.html</link><pubDate>Thu, 26 Jun 2008 12:23:17 +0800</pubDate><guid>http://blog.hnce.net/post/flash-transparent-in-Firefox-not-dispaly-solution.html</guid><description><![CDATA[<p>&#160;&#160;&#160;&#160;&#160;&#160; 这两天在做一个网站时需要用到透明背景的Flash效果，很久以前曾经用过，没有发现不正常的现像（可能是以前使用Firefox比较少）；昨天发现在Firefox中透明的Flash效果在IE中显示正常，但是在Firefox中却显示一团黑。于是在网上搜索发现只要在Flash代码中加入一个值就可以解决了，发上来与大家一起分享，希望对您有所帮助。</p>  <p>原来的代码：</p>  <p>&lt;embed pluginspage=&quot;htt p://www.macromedia.com/go/getflashplayer&quot; src=&quot;透明Flash地址&quot; width=&quot;950&quot; height=&quot;220&quot; type=&quot;application/x-shockwave-flash&quot; quality=&quot;high&quot;&#160; /&gt;</p>  <p>只要在里面加上参数并赋值：wmode=&quot;transparent&quot;即可解决，修改之后的代码为：</p>  <p>&lt;embed pluginspage=&quot;htt p://www.macromedia.com/go/getflashplayer&quot; src=&quot;透明Flash地址&quot; width=&quot;950&quot; height=&quot;220&quot; type=&quot;application/x-shockwave-flash&quot; quality=&quot;high&quot; wmode=&quot;transparent&quot; /&gt; </p>  <p>&#160;</p>  <p>关于wmode参数的具体使用有如下：</p>  <p><strong>window 模式      <br /></strong>    <br />默认情况下的显示模式，在这种模式下flash player有自己的窗口句柄，这就意味着flash影片是存在于Windows中的一个显示实例，并且是在浏览器核心显示窗口之上的，所以flash只是貌似显示在浏览器中，但这也是flash最快最有效率的渲染模式。由于他是独立于浏览器的HTML渲染表面，这就导致默认显示方式下flash总是会遮住位置与他重合的所有DHTML层。 </p>  <p>但是大多数苹果电脑浏览器会允许DHTML层显示在flash之上，但当flash影片播放时会出现比较诡异的现象，比如DHTML层像被flash刮掉一块一样显示异常。 </p>  <p><strong>Opaque 模式      <br /></strong>    <br />这是一种无窗口模式，在这种情况下flash player没有自己的窗口句柄，这就需要浏览器需要告诉flash player在浏览器的渲染表面绘制的时间和位置。这时flash影片就不会在高于浏览器HTML渲染表面而是与其他元素一样在同一个页面上,因此你就可以使用z-index值来控制DHTML元素是遮盖flash或者被遮盖。 </p>  <p><strong>Transparent 模式</strong>     <br />    <br />透明模式，在这种模式下flash player会将stage的背景色alpha值将为0并且只会绘制stage上真实可见的对象，同样你也可以使用z-index来控制flash影片的深度值，但是与Opaque模式不同的是这样做会降低flash影片的回放效果，而且在9.0.115之前的flash player版本设置wmode=&#8221;opaque&#8221;或&#8221;transparent&#8221;会导致全屏模式失效。</p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/flash-transparent-in-Firefox-not-dispaly-solution.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=395</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=395&amp;key=e4b6c503</trackback:ping></item><item><title>CSS实现完美垂直居中</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/229.html</link><pubDate>Sun, 26 Feb 2006 03:17:00 +0800</pubDate><guid>http://blog.hnce.net/post/229.html</guid><description><![CDATA[<p>之前看到很多人一直都问这个问题，不过当时我没当一回事，因为在 CSS 中要垂直居中，多数是在有高度的情况下，或者容器高度不定的情况下才用，看上去比较舒服，而且实现的方法也不少，不一定要拘泥于和 table 布局一样。不过最近有人问了几个例子，看来对此的需求还不少。现在就把我经验拿出来分享一下，希望大家鼓鼓掌。首先，要有一个概念：<b>凡是 table 布局可以实现的，CSS 一定可以实现</b>。CSS 可以实现的，table 未必能做到。<br />现在来几个例子：<br /><br /></p><p><b>一、单行内容的居中</b><br />只考虑单行是最简单的，无论是否给容器固定高度，只要给容器设置 <font color="#000099">line-height</font> 和 <font color="#000099">height</font>，并使两值相等，再加上 <font color="#000099">over-flow: hidden</font> 就可以了</p><p><span class="code">.middle-demo-1{<br />height: 4em;<br />line-height: 4em;<br />overflow: hidden;<br />} </span></p><p>优点：<br />1. 同时支持块级和内联极元素<br />2. 支持所有浏览器<br />缺点：<br />1. 只能显示一行<br />2. IE中不支持&lt;img&gt;等的居中<br />要注意的是：<br />1. 使用相对高度定义你的 height 和 line-height<br />2. 不想毁了你的布局的话，overflow: hidden 一定要<br />为什么？<br />请比较以下两个例子：<br />CODE:<br /><br />&lt;p style=&quot;background: #900; color: #00f; font: bold 12px/24px Helvertica,Arial,sans-serif; height:24px; width:370px;&quot;&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit.&lt;/p&gt;<br />&lt;br/&gt;<br />&lt;br/&gt;<br />&lt;p style=&quot;background: #090; color: #00f; font: bold 12px/2em Helvertica,Arial,sans-serif; height:2em; width:370px; overflow: hidden;&quot;&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit.&lt;/p&gt;<br /><br /><br /></p><p>上一个高度是用的绝对单位px，并且没有隐藏溢出，下一个高度用的单位是相对单位em，并且隐藏了溢出。如果你的浏览器支持放大字体，那么尽情地放大字体，看看会出现什么效果。</p><p><b>二、多行内容居中，且容器高度可变</b><br />也很简单，给出一致的 padding-bottom 和 padding-top 就行</p><p><span class="code">.middle-demo-2{<br />padding-top: 24px;<br />padding-bottom: 24px;<br />} </span></p><p>优点：<br />1. 同时支持块级和内联极元素<br />2. 支持非文本内容<br />3. 支持所有浏览器<br />缺点：<br />容器不能固定高度</p><p><b>三、把容器当作表格单元</b><br />CSS 提供一系列diplay属性值，包括 display: table, display: table-row, display: table-cell 等，能把元素当作表格单元来显示。这是再加上 vertical-align: middle, 就和表格中的 valign=&quot;center&quot; 一样了。</p><p><span class="code">.middle-demo-3{<br />display: table-cell;<br />height: 300px;<br />vertical-align: middle;<br />}</span> </p><p>可惜IE不支持这些属性，不过在其他浏览器上显示效果非常完美。<br />要注意的是：和一个合法的&lt;td&gt;元素必须在&lt;table&gt;里一样，display: table-cell 元素必须作为 display: table 的元素的子孙出现。</p><p>优点：<br />不用说了吧，就是表格，效果和表格一模一样<br />缺点：<br />IE下无效</p><p><b>四、以毒攻毒！用 IE 的 bug 解决 IE 中的绝对居中</b><br />先不得不说一句，IE 真的是个很烂的浏览器，CSS1中的定义都不支持，害得要我们转个大圈子来造居中。不过就像我说的，<b>凡是 table 布局可以实现的，CSS 一定可以实现</b>，即使在 IE 里也不例外。我研究 IE layout 模式多年，还是找出了一个可以在 IE 中绝对居中的方法。这个方法就是基于 IE layout 的 bug，也可以算以毒攻毒。至于原理，不要问我，这是独门秘学，何况三言两语也讲不清楚，只要好用就行</p><p><span class="code">.middle-demo-4{<br />height: 300px;<br />position: relative;<br />}<br />.middle-demo-4 div{<br />position: absolute;<br />top: 50%;<br />left: 0;<br />}<br />.middle-demo-4 div div{<br />position: relative;<br />top: -50%;<br />left: 0;<br />} </span></p><p><b>五、整合三和四，写出支持所有浏览器的垂直居中容器！</b><br />思路是利用 IE 和 非IE 浏览器的 CSS hack, 整合三和四的CSS，写出兼容主流浏览器的垂直居中容器。具体代码就不给出了，大家权当作练习练习。例子可以在下面的附录中找到。<br />最终实测支持的浏览器：IE6+, Mozilla 1.7, Netscape Navigator 8, Opera 8.0+, Firefox 1.0+ 和 Safari 1.0+IE5 下需要加上对合适模型的补正。<br />推测支持的浏览器：Mozilla 1.5+, Netscape Navigator 7+, Opera 7+<br />未测试浏览器：Konqueror</p><p>范例页面：<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</a>&quot;&gt;<br />&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>&quot; xml:lang=&quot;en&quot;&gt;<br />&lt;head&gt;<br />&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />&lt;title&gt;Demo:: vertical align: middle&lt;/title&gt;<br />&lt;meta lang=&quot;en&quot; name=&quot;author&quot; content=&quot;Spenser Lee&quot; /&gt;<br />&lt;meta lang=&quot;en&quot; name=&quot;copyright&quot; content=&quot;(c)2006 Liberty Studio&quot; /&gt;<br />&lt;style media=&quot;screen&quot; type=&quot;text/css&quot;&gt;<br />html,body,div,h1,h2,pre,dd,ol{margin: 0;padding: 0;border: 0}<br />html{min-width: 779px}<br />body{background: #fff;color: #596480;text-align: center}<br />div#main-wrapper{padding: 12px 5px;width: 769px;margin: 0 auto}<br />div,code,p,h1,h2,address,dt,dd,li{font: normal 12px/1.5em Tahoma,&quot;Lucida Grande&quot;,Helvetica,Verdana,Lucida,Arial,&quot;Arial Unicode&quot;,sans-serif,serif}<br />h1{font-size: 22px;font-weight: bold;border-left: 12px solid #324f96;background: #e0eaf4;color: #4868a9;height: 4em;line-height: 4em;padding: 0 12px;overflow: hidden; text-align: left}<br />h2{font-size: 12px;font-weight: bold;background: #c0014e;color: #fff;height: 2.5em;line-height: 2.5em;padding: 0 24px;overflow: hidden;margin: 12px 0;text-align: left}<br />h2 a{color: #fff;background: transparent}<br />h2 a:hover{text-decoration: none}<br />p{margin: 6px 0;padding: 0 12px 0 24px;text-indent: 2em;text-align: left}<br />p.snap-back{text-align: right}<br />code{display: block;font-family: &quot;Courier New&quot;, Courier, monospace, mono, serif;margin: 12px auto;padding: 12px;border: 1px solid #596480;color: inherit;background: #f6f6f6;text-align: left;white-space: pre;width: 350px}<br />strong{font-weight: bold}<br />em{font-style: italic}<br />address{display: block;padding: 0 12px;margin: 12px 0;text-align: right}<br />dl{margin: 6px 0;padding: 0 12px 0 24px;text-align: left}<br />dt{margin: 0;text-indent: 2em;font-weight: bold}<br />dd{margin-left: 24px;text-indent: 2em}<br />li{list-style: square inside none;text-align: left}<br />ol#table-of-content{padding-left: 24px}<br />a{color: #c0014e;background: transparent;text-decoration: none}<br />a:hover{text-decoration: underline}<br />div.demo{width: 400px;margin: 12px auto;border: 1px solid #596480;color: inherit;background: #ffc}<br />div.demo p{text-align: left;margin: 24px;text-indent: 0}<br />p#demo-1{margin: 12px auto;padding: 0 12px;width: 400px;text-indent: 0;border: 1px solid #596480;color: inherit;background: #ffc;line-height: 4em;height: 4em;overflow: hidden}<br />div#demo-2{padding: 50px 0}<br />div#demo-4, div#demo-5{height: 300px;position: relative}<br />div#demo-4 div, div#demo-5 div{position: absolute;top: 50%;left: 0}<br />div#demo-4 p, div#demo-5 p{position: relative;top: -50%}<br />div#demo-3{display: table;height: 300px;border-collapse: collapse}<br />div#main-wrapper&gt;div#demo-5{position: static;display:table}<br />div#main-wrapper&gt;div#demo-5&gt;div{display:table-cell;vertical-align:middle;position:static}<br />div#demo-3&gt;div{display: table-row}<br />div#demo-3&gt;div&gt;div{display: table-cell;vertical-align: middle}<br />span.property{font-family: &quot;Courier New&quot;, Courier, monospace, mono, serif;border-bottom: 1px dotted #596480;background: #ffc;color: #c0014e}<br />p.copyright{line-height: 3em;text-align: center;border-top: 1px dotted #596480}<br />&lt;/style&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&lt;div id=&quot;main-wrapper&quot;&gt;<br />&lt;h1&gt;Demo of middled vertical align&lt;/h1&gt;<br />&lt;address&gt;<br />&nbsp;Author: Spenser Lee, Liberty Studio&lt;br /&gt;<br />&nbsp;Originally posted on &lt;a href=&quot;<a href="http://www.blueidea.com/bbs/">http://www.blueidea.com/bbs/</a>&quot; title=&quot;BlueIdea Forum&quot;&gt;BlueIdea Forum&lt;/a&gt;<br />&lt;/address&gt;<br />&lt;h2&gt;&lt;a id=&quot;bullet-0&quot;&gt;Table of centents:&lt;/a&gt;&lt;/h2&gt;<br />&lt;ol id=&quot;table-of-content&quot;&gt;<br />&nbsp;&lt;li&gt;&lt;a href=&quot;#bullet-1&quot; title=&quot;Single line countainer with/without a fixed height&quot;&gt;Single line countainer with/without a fixed height&lt;/a&gt;&lt;/li&gt;<br />&nbsp;&lt;li&gt;&lt;a href=&quot;#bullet-2&quot; title=&quot;Align multi-line container which does not have a fixed height&quot;&gt;Align multi-line container which does not have a fixed height&lt;/a&gt;&lt;/li&gt;<br />&nbsp;&lt;li&gt;&lt;a href=&quot;#bullet-3&quot; title=&quot;Simulating table layout in container with a fixed height&quot;&gt;Simulating table layout in container with a fixed height&lt;/a&gt;&lt;/li&gt;<br />&nbsp;&lt;li&gt;&lt;a href=&quot;#bullet-4&quot; title=&quot;IE&#39;s solution&quot;&gt;IE&#39;s solution&lt;/a&gt;&lt;/li&gt;<br />&nbsp;&lt;li&gt;&lt;a href=&quot;#bullet-5&quot; title=&quot;A perfect compounded sample&quot;&gt;A perfect compounded sample&lt;/a&gt;&lt;/li&gt;<br />&lt;/ol&gt;<br />&lt;h2&gt;&lt;a id=&quot;bullet-1&quot;&gt;Case One: Single line countainer with/without a fixed height&lt;/a&gt;&lt;/h2&gt;<br />&lt;p&gt;If you only want to display a container which only holds a single line of text, you can set &lt;span class=&quot;property&quot;&gt;line-height&lt;/span&gt; property to &lt;span class=&quot;property&quot;&gt;height&lt;/span&gt; property, then set &lt;span class=&quot;property&quot;&gt;overflow&lt;/span&gt; to hidden.&lt;/p&gt;<br />&lt;p&gt;&lt;strong&gt;Sample:&lt;/strong&gt;&lt;/p&gt;<br />&lt;p id=&quot;demo-1&quot;&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit.&lt;/p&gt;<br />&lt;p&gt;&lt;strong&gt;Core code:&lt;/strong&gt;&lt;/p&gt;<br />&lt;pre&gt;&lt;code&gt;.middle-demo-1{<br />&nbsp;height: 4em;<br />&nbsp;line-height: 4em;<br />&nbsp;overflow: hidden;<br />}&lt;/code&gt;&lt;/pre&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Notes:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;I strongly recommend you use relative size in &lt;span class=&quot;property&quot;&gt;height&lt;/span&gt; and &lt;span class=&quot;property&quot;&gt;line-height&lt;/span&gt; property. &lt;em&gt;Why?&lt;/em&gt; You can simply set the font size larger if your browser support it. When it gets large enough, you will see the countainer is stretched and the &lt;span class=&quot;property&quot;&gt;height&lt;/span&gt; is no longer equal to &lt;span class=&quot;property&quot;&gt;line-height&lt;/span&gt; property, thus, the layout is messed up. Using relative size as &lt;span class=&quot;property&quot;&gt;em, ex&lt;/span&gt; or &lt;span class=&quot;property&quot;&gt;%&lt;/span&gt; will let your countainer stretch with the content.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;&lt;span class=&quot;property&quot;&gt;overflow: hidden&lt;/span&gt; is a must. &lt;em&gt;Why?&lt;/em&gt; Same as above. Just ensure &lt;span class=&quot;property&quot;&gt;height&lt;/span&gt; and &lt;span class=&quot;property&quot;&gt;line-height&lt;/span&gt; are always equal.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Pros:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;Fits in both &lt;span class=&quot;property&quot;&gt;block&lt;/span&gt; elements and &lt;span class=&quot;property&quot;&gt;inline&lt;/span&gt; elements.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Capable of all 5th-gen browsers.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Cons:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;Text length is limited. Max with only &lt;em&gt;one&lt;/em&gt; line.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Does not work well on none text contents such as images and objects.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;p class=&quot;snap-back&quot;&gt;&lt;a href=&quot;#bullet-0&quot; title=&quot;Back top table of centents&quot;&gt;Back&lt;/a&gt;&lt;/p&gt;<br />&lt;h2&gt;&lt;a id=&quot;bullet-2&quot;&gt;Case Two: Align multi-line container which does not have a fixed height&lt;/a&gt;&lt;/h2&gt;<br />&lt;p&gt;In this case, we should simply set a pair of fixed equivalences to padding-top and padding-bottom attribute. It works on both IE and non-IE browsers.&lt;/p&gt;<br />&lt;p&gt;&lt;strong&gt;Sample:&lt;/strong&gt;&lt;/p&gt;<br />&lt;div class=&quot;demo&quot; id=&quot;demo-2&quot;&gt;<br />&nbsp;&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas dignissim diam eu sem. Proin nunc ante, accumsan sollicitudin, sodales at, semper sed, ipsum. Etiam orci. Vestibulum magna lectus, venenatis nec, tempus ac, dictum vel, lorem.&lt;/p&gt;<br />&lt;/div&gt;<br />&lt;p&gt;&lt;strong&gt;Core code:&lt;/strong&gt;&lt;/p&gt;<br />&lt;pre&gt;&lt;code&gt;.middle-demo-2{<br />&nbsp;padding-top: 24px;<br />&nbsp;padding-bottom: 24px;<br />}&lt;/code&gt;&lt;/pre&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Pros:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;Fits in both &lt;span class=&quot;property&quot;&gt;block&lt;/span&gt; elements and &lt;span class=&quot;property&quot;&gt;inline&lt;/span&gt; elements.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Works on none text contents as fine as text contents.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Capable of all 5th-gen browsers. Might need a little tune-up for the box model bug of IE5 though.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Cons:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;You can &lt;em&gt;not&lt;/em&gt; assign height in this solution.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;p class=&quot;snap-back&quot;&gt;&lt;a href=&quot;#bullet-0&quot; title=&quot;Back top table of centents&quot;&gt;Back&lt;/a&gt;&lt;/p&gt;<br />&lt;h2&gt;&lt;a id=&quot;bullet-3&quot;&gt;Case Three: Simulating table layout in container with a fixed height&lt;/a&gt;&lt;/h2&gt;<br />&lt;p&gt;CSS offers a set of very convenient display atrribute values called &lt;span class=&quot;property&quot;&gt;display: table&lt;/span&gt;, &lt;span class=&quot;property&quot;&gt;display: table-row&lt;/span&gt;, &lt;span class=&quot;property&quot;&gt;display: table-cell&lt;/span&gt; and other display values begin with &lt;span class=&quot;property&quot;&gt;table-&lt;/span&gt;. It offers a way to simulate table layout in all elements. As a result, any element with &lt;span class=&quot;property&quot;&gt;display: table-cell&lt;/span&gt;, &lt;span class=&quot;property&quot;&gt;vertical-align: middle&lt;/span&gt; and a fixed height will display exactly like a table cell.&lt;/p&gt;<br />&lt;p&gt;&lt;strong&gt;Sample:&lt;/strong&gt; (You may not be able to view the effect on IE)&lt;/p&gt;<br />&lt;div class=&quot;demo&quot; id=&quot;demo-3&quot;&gt;<br />&nbsp;&lt;div&gt;&lt;div&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas dignissim diam eu sem. Proin nunc ante, accumsan sollicitudin, sodales at, semper sed, ipsum. Etiam orci. Vestibulum magna lectus, venenatis nec, tempus ac, dictum vel, lorem.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;<br />&lt;/div&gt;<br />&lt;p&gt;&lt;strong&gt;Core code:&lt;/strong&gt;&lt;/p&gt;<br />&lt;pre&gt;&lt;code&gt;.middle-demo-3{<br />&nbsp;display: table-cell;<br />&nbsp;height: 300px;<br />&nbsp;vertical-align: middle;<br />}&lt;/code&gt;&lt;/pre&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Notes:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;&lt;span class=&quot;property&quot;&gt;display: table-cell&lt;/span&gt; must work with other elements with &lt;span class=&quot;property&quot;&gt;display: table&lt;/span&gt; value sets in order to form a literal table. Or it might cause unexceptable bugs.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Sadly IE series (including the latest IE 7 beta) does not support any of &lt;span class=&quot;property&quot;&gt;display: table&lt;/span&gt; values, so it won&#39;t work in IE.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Pros:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;It has the most perfect render for &lt;span class=&quot;property&quot;&gt;vertical-align: middle&lt;/span&gt; align.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Cons:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;It only works in latest versions of non-IE browsers, such as Mozilla, Firefox, Netscape 8, Opera 8, and Safari.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;p class=&quot;snap-back&quot;&gt;&lt;a href=&quot;#bullet-0&quot; title=&quot;Back top table of centents&quot;&gt;Back&lt;/a&gt;&lt;/p&gt;<br />&lt;h2&gt;&lt;a id=&quot;bullet-4&quot;&gt;Case Four: IE&#39;s solution&lt;/a&gt;&lt;/h2&gt;<br />&lt;p&gt;Since IE is a lame browser when it comes to ANYTHING, so you can&#39;t use the solution above simply because IE does not recognize it at all. However, &lt;strong&gt;there has been nothing yet you can not code with CSS if you have already coded it with table&lt;/strong&gt;. It even offers you possibility to layout your page that tables can not do!&lt;/p&gt;<br />&lt;p&gt;So what&#39;s the solution for IE? Like what we always do: Hit IE&#39;s back with the BUGS it offers!&lt;/p&gt;<br />&lt;p&gt;&lt;strong&gt;Sample:&lt;/strong&gt; (You are able to view the correct result only on IE)&lt;/p&gt;<br />&lt;div class=&quot;demo&quot; id=&quot;demo-4&quot;&gt;<br />&nbsp;&lt;div&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas dignissim diam eu sem. Proin nunc ante, accumsan sollicitudin, sodales at, semper sed, ipsum. Etiam orci. Vestibulum magna lectus, venenatis nec, tempus ac, dictum vel, lorem.&lt;/p&gt;&lt;/div&gt;<br />&lt;/div&gt;<br />&lt;pre&gt;&lt;code&gt;.middle-demo-4{<br />&nbsp;height: 300px;<br />&nbsp;position: relative;<br />}<br />.middle-demo-4 div{<br />&nbsp;position: absolute;<br />&nbsp;top: 50%;<br />&nbsp;left: 0;<br />}<br />.middle-demo-4 div div{<br />&nbsp;position: relative;<br />&nbsp;top: -50%;<br />&nbsp;left: 0;<br />}&lt;/code&gt;&lt;/pre&gt;<br />&lt;p&gt;See? Don&#39;t ask me why it worked. This hack is based on years of study in IE&#39;s own stupid layout model and it works very well, even in IE5 given the box width hack. I won&#39;t tell you the theory behind all these. It&#39;s my top secret, with which I solved a lot of other cross browser layout problems, and I&#39;m not going to share it with you. But you are free to use this IE hack It&#39;s kinda handful in most occassions.&lt;/p&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Pros:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;The only perfect vertical align method in IE. It works even better then add automatic &lt;span class=&quot;property&quot;&gt;padding&lt;/span&gt;s.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Cons:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;After all it&#39;s a CSS hack. We can avoid it if not for IE.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;p class=&quot;snap-back&quot;&gt;&lt;a href=&quot;#bullet-0&quot; title=&quot;Back top table of centents&quot;&gt;Back&lt;/a&gt;&lt;/p&gt;<br />&lt;h2&gt;&lt;a id=&quot;bullet-5&quot;&gt;Case Five: A perfect compounded sample&lt;/a&gt;&lt;/h2&gt;<br />&lt;p&gt;Here&#39;s the perfect compounded solution on vertical centering that works on almost all latest browsers.&lt;/p&gt;<br />&lt;p&gt;&lt;strong&gt;Sample:&lt;/strong&gt; (This works on almost all browsers)&lt;/p&gt;<br />&lt;div class=&quot;demo&quot; id=&quot;demo-5&quot;&gt;<br />&nbsp;&lt;div&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas dignissim diam eu sem. Proin nunc ante, accumsan sollicitudin, sodales at, semper sed, ipsum. Etiam orci. Vestibulum magna lectus, venenatis nec, tempus ac, dictum vel, lorem.&lt;/p&gt;&lt;/div&gt;<br />&lt;/div&gt;<br />&lt;p&gt;I&#39;m not going to give you the full code of this one. But it&#39;s not difficult to write it yourself, with the solution of case 3 and 4, and a little knowledge in IE/non-IE CSS hackers. And actually the hacking style is not limited, so I don&#39;t want to force you to use my hacking style neither. Stop being lazy, and write the code yourself!&lt;/p&gt;<br />&lt;dl&gt;<br />&nbsp;&lt;dt&gt;Browser capability:&lt;/dt&gt;<br />&nbsp;&lt;dd&gt;<br />&nbsp; &lt;ol&gt;<br />&nbsp;&nbsp; &lt;li&gt;Works on: IE6+, Mozilla 1.5+, Netscape Navigator 7+, Opera 7+, Firefox 1.0+ and Safari 1.0+&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;On IE5, you might need to apply the box model hacker to make the height correct.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Untested: WebOmini, Konqueror.&lt;/li&gt;<br />&nbsp;&nbsp; &lt;li&gt;Fails on: Other browsers not reffered in the list above.&lt;/li&gt;<br />&nbsp; &lt;/ol&gt;<br />&nbsp;&lt;/dd&gt;<br />&lt;/dl&gt;<br />&lt;p class=&quot;snap-back&quot;&gt;&lt;a href=&quot;#bullet-0&quot; title=&quot;Back top table of centents&quot;&gt;Back&lt;/a&gt;&lt;/p&gt;<br />&lt;p class=&quot;copyright&quot;&gt;Copyright &amp;copy; Spenser Lee, 2006 Liberty Studio&lt;/p&gt;<br />&lt;/div&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br /><br /></p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/229.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=229</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=229&amp;key=fb886ae4</trackback:ping></item><item><title>细说HTML元素的ID和Name属性的区别</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/214.html</link><pubDate>Tue, 17 Jan 2006 22:51:00 +0800</pubDate><guid>http://blog.hnce.net/post/214.html</guid><description><![CDATA[<h3>细说HTML元素的ID和Name属性的区别</h3>可以说几乎每个做过Web开发的人都问过，到底元素的ID和Name有什么区别阿？为什么有了ID还要有Name呢?!&nbsp;而同样我们也可以得到最 classical的答案：ID就像是一个人的身份证号码，而Name就像是他的名字，ID显然是唯一的，而Name是可以重复的。<p> &nbsp;&nbsp;&nbsp;&nbsp;上周我也遇到了ID和Name的问题，在页面里输入了一个input&nbsp;type=&quot;hidden&quot;，只写了一个ID='SliceInfo'，赋 值后submit，在后台用Request.Params[&quot;SliceInfo&quot;]却怎么也去不到值。后来恍然大悟因该用Name来标示，于是在 input里加了个Name='SliceInfo'，就一切ok了。</p><p> &nbsp;&nbsp;&nbsp;&nbsp;第一段里对于ID和Name的解答说的太笼统了，当然那个解释对于ID来说是完全对的，它就是Client端HTML元素的Identity。而Name其实要复杂的多，因为Name有很多种的用途，所以它并不能完全由ID来代替，从而将其取消掉。具体用途有：</p><p> &nbsp;&nbsp;&nbsp;&nbsp;用途1:&nbsp;作为可与服务器交互数据的HTML元素的服务器端的标示，比如input、select、textarea、和button等。我们可以在服务器端根据其Name通过Request.Params取得元素提交的值。<br />&nbsp;&nbsp;&nbsp;&nbsp;用途2:&nbsp;HTML元素Input&nbsp;type='radio'分组，我们知道radio&nbsp;button控件在同一个分组类，check操作是mutex的，同一时间只能选中一个radio，这个分组就是根据相同的Name属性来实现的。<br />&nbsp;&nbsp;&nbsp;&nbsp;用途3:&nbsp;建立页面中的锚点，我们知道&lt;a&nbsp;href=&quot;URL&quot;&gt;link&lt;/a&gt;是获得一个页面超级链接，如果不用 href属性，而改用Name，如：&lt;a&nbsp;name=&quot;PageBottom&quot;&gt;&lt;/a&gt;，我们就获得了一个页面锚点。<br />&nbsp;&nbsp;&nbsp;&nbsp;用途4:&nbsp;作为对象的Identity，如Applet、Object、Embed等元素。比如在Applet对象实例中，我们将使用其Name来引用该对象。<br />&nbsp;&nbsp;&nbsp;&nbsp;用途5:&nbsp;在IMG元素和MAP元素之间关联的时候，如果要定义IMG的热点区域，需要使用其属性usemap，使usemap=&quot;#name&quot;(被关联的MAP元素的Name)。<br />&nbsp;&nbsp;&nbsp;&nbsp;用途6:&nbsp;某些特定元素的属性，如attribute，meta和param。例如为Object定义参数&lt;PARAM&nbsp;NAME&nbsp;=&nbsp;&quot;appletParameter&quot;&nbsp;<em>value</em>&nbsp;=&nbsp;&quot;<em>value</em>&quot;&gt;或Meta中&lt;META&nbsp;NAME&nbsp;=&nbsp;&quot;Author&quot;&nbsp;CONTENT&nbsp;=&nbsp;&quot;Dave&nbsp;Raggett&quot;&gt;。</p><p> &nbsp;&nbsp;&nbsp;&nbsp;显然这些用途都不是能简单的使用ID来代替掉的，所以HTML元素的ID和Name的却别并不是身份证号码和姓名这样的区别，它们更本就是不同作用的东西。</p><p> &nbsp;&nbsp;&nbsp;&nbsp;当然HTML元素的Name属性在页面中也可以起那么一点ID的作用，因为在DHTML对象树中，我们可以使用 document.getElementsByName来获取一个包含页面中所有指定Name元素的对象数组。Name属性还有一个问题，当我们动态创建 可包含Name属性的元素时，不能简单的使用赋值element.name&nbsp;=&nbsp;&quot;...&quot;来添加其Name，而必须在创建Element时，使用 document.createElement('&lt;element&nbsp;name&nbsp;=&nbsp;&quot;myName&quot;&gt;&lt;/element&gt;') 为元素添加Name属性。这是什么意思啊？看下面的例子就明白了。</p><p> &lt;script&nbsp;language=&quot;<em>javascript</em>&quot;&gt;<br />var&nbsp;input&nbsp;=&nbsp;document.createElement('INPUT');<br />input.id&nbsp;=&nbsp;'myId';<br />input.name&nbsp;=&nbsp;'myName';<br />alert(input.outerHTML);<br />&lt;/script&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;消息框里显示的结果是：&lt;INPUT&nbsp;id=myId&gt;。</p><p> &lt;script&nbsp;language=&quot;<em>javascript</em>&quot;&gt;<br />var&nbsp;input&nbsp;=&nbsp;document.createElement('&lt;INPUT&nbsp;name=&quot;myName&quot;&gt;');<br />input.id&nbsp;=&nbsp;'myId';<br />alert(input.outerHTML);<br />&lt;/script&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;消息框里显示的结果是：&lt;INPUT&nbsp;id=myId&nbsp;name=myName&gt;。<br />&nbsp;&nbsp;&nbsp;&nbsp;初始化Name属性的这个设计不是IE的缺陷，因为MSDN里说了要这么做的，可是这样设计的原理什么呢？我暂时没有想太明白。</p>&nbsp;&nbsp;&nbsp;&nbsp;这里再顺便说一下，要是页面中有n(n&gt;1)个HTML元素的ID都相同了怎么办？在DHTML对象中怎么引用他们呢？如果我们使用 ASPX页面，这样的情况是不容易发生的，因为aspnet进程在处理aspx页面时根本就不允许有ID非唯一，这是页面会被抛出异常而不能被正常的 render。要是不是动态页面，我们硬要让ID重复那IE怎么搞呢？这个时候我们还是可以继续使用document.getElementById获取 对象，只不过我们只能获取ID重复的那些对象中在HTML&nbsp;Render时第一个出现的对象。而这时重复的ID会在引用时自动变成一个数组，ID重复的元 素按Render的顺序依次存在于数组中。]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/214.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=214</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=214&amp;key=052150cb</trackback:ping></item><item><title>HTML中小meta的大作用</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/50.html</link><pubDate>Tue, 30 Aug 2005 14:05:00 +0800</pubDate><guid>http://blog.hnce.net/post/50.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;meta是用来在HTML文档中模拟HTTP协议的响应头报文。meta 标签用于网页的&lt;head&gt;与&lt;/head&gt;中，meta 标签的用处很多。meta 的属性有两种：name和http-equiv。name属性主要用于描述网页，对应于content（网页内容），以便于搜索引擎机器人查找、分类（目前几乎所有的搜索引擎都使用网上机器人自动查找meta值来给网页分类）。这其中最重要的是description（站点在搜索引擎上的描述）和keywords（分类关键词），所以应该给每页加一个meta值。比较常用的有以下几个： <br /><br />name 属性<br/><p>　　1、&lt;meta name=&quot;Generator&quot; contect=&quot;&quot;&gt;用以说明生成工具（如Microsoft FrontPage 4.0）等； </p><p>　　2、&lt;meta name=&quot;KEYWords&quot; contect=&quot;&quot;&gt;向搜索引擎说明你的网页的关键词； </p><p>　　3、&lt;meta name=&quot;DEscription&quot; contect=&quot;&quot;&gt;告诉搜索引擎你的站点的主要内容； </p><p>　　4、&lt;meta name=&quot;Author&quot; contect=&quot;你的姓名&quot;&gt;告诉搜索引擎你的站点的制作的作者； </p><p>　　5、&lt;meta name=&quot;Robots&quot; contect= &quot;all|none|index|noindex|follow|nofollow&quot;&gt; </p><p>　　其中的属性说明如下： </p><p>　　设定为all：文件将被检索，且页面上的链接可以被查询； </p><p>　　设定为none：文件将不被检索，且页面上的链接不可以被查询； </p><p>　　设定为index：文件将被检索； </p><p>　　设定为follow：页面上的链接可以被查询； </p><p>　　设定为noindex：文件将不被检索，但页面上的链接可以被查询； </p><p>　　设定为nofollow：文件将不被检索，页面上的链接可以被查询。 </p><p>　　http-equiv属性 </p><p>　　1、&lt;meta http-equiv=&quot;Content-Type&quot; contect=&quot;text/html&quot;;charset=gb_2312-80&quot;&gt; </p><p>和 &lt;meta http-equiv=&quot;Content-Language&quot; contect=&quot;zh-CN&quot;&gt;用以说明主页制作所使用的文字以及语言； </p><p>　　又如英文是ISO-8859-1字符集，还有BIG5、utf-8、shift-Jis、Euc、Koi8-2等字符集； </p><p>　　2、&lt;meta http-equiv=&quot;Refresh&quot; contect=&quot;n;url=http://yourlink&quot;&gt;定时让网页在指定的时间n内，跳转到页面<a href="http://yourlink/">http://yourlink</a>； </p><p>　　3、&lt;meta http-equiv=&quot;Expires&quot; contect=&quot;Mon,12 May 2001 00:20:00 GMT&quot;&gt;可以用于设定网页的到期时间，一旦过期则必须到服务器上重新调用。需要注意的是必须使用GMT时间格式； </p><p>　　4、&lt;meta http-equiv=&quot;Pragma&quot; contect=&quot;no-cache&quot;&gt;是用于设定禁止浏览器从本地机的缓存中调阅页面内容，设定后一旦离开网页就无法从Cache中再调出； </p><p>　　5、&lt;meta http-equiv=&quot;set-cookie&quot; contect=&quot;Mon,12 May 2001 00:20:00 GMT&quot;&gt;cookie设定，如果网页过期，存盘的cookie将被删除。需要注意的也是必须使用GMT时间格式； </p><p>　　6、&lt;meta http-equiv=&quot;Pics-label&quot; contect=&quot;&quot;&gt;网页等级评定，在IE的internet选项中有一项内容设置，可以防止浏览一些受限制的网站，而网站的限制级别就是通过meta属性来设置的； </p><p>　　7、&lt;meta http-equiv=&quot;windows-Target&quot; contect=&quot;_top&quot;&gt;强制页面在当前窗口中以独立页面显示，可以防止自己的网页被别人当作一个frame页调用； </p><p>　　8、&lt;meta http-equiv=&quot;Page-Enter&quot; contect=&quot;revealTrans(duration=10,transtion= 50)&quot;&gt;和&lt;meta http-equiv=&quot;Page-Exit&quot; contect=&quot;revealTrans(duration=20，transtion=6)&quot;&gt;设定进入和离开页面时的特殊效果，这个功能即FrontPage中的&ldquo;格式/网页过渡&rdquo;，不过所加的页面不能够是一个frame页面。 </p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/50.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=50</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=50&amp;key=4476b3a1</trackback:ping></item><item><title>加快 DHTML 的一组技巧</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/47.html</link><pubDate>Tue, 30 Aug 2005 13:43:00 +0800</pubDate><guid>http://blog.hnce.net/post/47.html</guid><description><![CDATA[<p>动态 HTML (DHTML) 在 Microsoft&reg; Internet Explorer 4.0 中的引入，使 Web 作者和开发人员可以使用新的编程模型。此后，Web 作者充分利用了这个强大的特性来提供动态内容、样式和定位，使 Web 用户得以体验丰富的交互式功能。DHTML 的灵活性使得通常会有多种方式可以实现您的构思。理解 Internet Explorer 的 HTML 分析和显示组件如何处理请求，可帮助您确定完成工作的最佳方法。本文介绍了某些 DHTML 功能对性能的重大影响，并提供了一些提高页面性能的技巧。<br /><br /><br /><b>摘要：</b>本文说明了某些 DHTML 功能对性能的重大影响，并提供了一些提高 DHTML 页面性能的技巧。</p><p><b>目录</b></p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic1">简介</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic2">成批处理 DHTML 更改</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic3">使用 innerText</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic4">使用 DOM 添加单个元素</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic5">扩展 SELECT 元素中的选项</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic6">用 DOM 更新表</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic7">编写一次，使用多次</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic8">请勿过多使用动态属性</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic9">数据绑定很有效</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic10">不要在 document 对象中设置 expando 属性</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic10a">避免切换类和样式规则</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic11">查找父项之前，先折叠文本范围</a><br /><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/dhtmlperf.asp#dhtmlperf_topic12">其他资料</a></p><h2><a name="dhtmlperf_topic1"></a>简介</h2><p>动态 HTML (DHTML) 在 Microsoft&reg; Internet Explorer 4.0 中的引入，使 Web 作者和开发人员可以使用新的编程模型。此后，Web 作者充分利用了这个强大的特性来提供动态内容、样式和定位，使 Web 用户得以体验丰富的交互式功能。DHTML 的灵活性使得通常会有多种方式可以实现您的构思。理解 Internet Explorer 的 HTML 分析和显示组件如何处理请求，可帮助您确定完成工作的最佳方法。本文介绍了某些 DHTML 功能对性能的重大影响，并提供了一些提高页面性能的技巧。</p><h2><a name="dhtmlperf_topic2"></a>成批处理 DHTML 更改</h2><p>在 DHTML Web 页面上，提高性能的最有效方法是改进对页面上 HTML 内容的更改。有多种方法可以更新 Web 页面，了解这一点非常重要。从客户的反馈来看，Web 作者可以应用 HTML 文本块，也可以通过使用 <a href="http://msdn.microsoft.com/workshop/author/om/doc_object.asp">DHTML 对象模型</a>（英文）或 <a href="http://msdn.microsoft.com/workshop/author/dom/domoverview.asp">W3C 文档对象模型 (DOM)</a>（英文）来访问个别 HTML 元素。无论何时更改 HTML 内容，Internet Explorer 的 HTML 分析和显示组件都必须重新组织该页面的内部表现形式，重新计算文档布局和文档流，并显示这些变化。虽然实际性能由 Web 页面的内容和您所作的更改决定，但是这些操作代价都比较大。如果您应用 HTML 文本块，而不是个别访问元素，则必须调用 HTML 分析器，这将导致额外的性能开销。接受 HTML 文本的方法和属性包括 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertAdjacentHTML.asp">insertAdjacentHTML</a>（英文）和 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/pasteHTML.asp">pasteHTML</a>（英文）方法，以及 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerHTML.asp">innerHTML</a>（英文）和 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/outerHTML.asp">outerHTML</a>（英文）属性。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 1：</b>在一个脚本函数中对 HTML 内容进行更改。如果您的设计使用了多个事件处理程序（例如响应鼠标移动），则应集中进行更改。</td>        </tr>    </tbody></table><br /></p><p>HTML 分析和显示组件的另一项重要事实是：一旦脚本返回控制（例如，当脚本事件处理函数退出时，或者当调用 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/setTimeout.asp">setTimeout</a>（英文）等方法时），该组件将重新计算布局并显示 Web 页面。现在，您已经了解 Internet Explorer 如何处理变化，下面将开始提高 Web 页面的性能。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 2：</b>建立一个 HTML 字符串并对文档进行一次更改，而不是进行多次更新。如果 HTML 内容不是必要的，可考虑使用 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerText.asp">innerText</a>（英文）属性。</td>        </tr>    </tbody></table><br /></p><p>在以下示例中，速度较慢的方法每次设置 <b>innerHTML</b> 属性时都调用 HTML 分析器。要提高性能，可以先建立一个字符串，然后将其分配给 <b>innerHTML</b> 属性。</p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/tip2.asp">请显示</a></p><p><b>慢：</b></p><pre class="clsCode"> divUpdate.innerHTML = &quot;&quot;;<br/>for ( var i=0; i&lt;100; i++ )<br/>{<br/>divUpdate.innerHTML += &quot;&lt;SPAN&gt;这是一个较慢的方法！&lt;/SPAN&gt;&quot;;<br/>}<br/></pre><p><b>快：</b></p><pre class="clsCode"> var str=&quot;&quot;;<br/>for ( var i=0; i&lt;100; i++ )<br/>{<br/>str += &quot;&lt;SPAN&gt;因为使用字符串，此方法较快！&lt;/SPAN&gt;&quot;;<br/>}<br/>divUpdate.innerHTML = str;<br/></pre><p>有关详细信息，请参见<a href="http://msdn.microsoft.com/workshop/author/dyncontent/content.asp">动态内容</a>（英文）。</p><h2><a name="dhtmlperf_topic3"></a>使用 innerText</h2><p>DHTML 对象模型通过 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerText.asp">innerText</a>（英文）属性访问 HTML 元素的文本内容，而 W3C DOM 则提供一个独立的子文本节点。直接通过 <b>innerText</b> 属性更新元素的内容，比调用 DOM <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createTextNode.asp">createTextNode</a>（英文）方法更快。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 3：</b>使用 <b>innerText</b> 属性更新文本内容。</td>        </tr>    </tbody></table><br /></p><p>以下示例显示了如何使用 <b>innerText</b> 属性提高性能。</p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/tip3.asp">请显示</a></p><p><b>慢：</b></p><pre class="clsCode"> var node;<br/>for (var i=0; i&lt;100; i++)<br/>{<br/>node = document.createElement( &quot;SPAN&quot; );<br/>node.appendChild(  document.createTextNode( &quot;使用 createTextNode() &quot;) );<br/>divUpdate.appendChild( node );<br/>}<br/></pre><p><b>快：</b></p><pre class="clsCode"> var node;<br/>for (var i=0; i&lt;100; i++)<br/>{<br/>node = document.createElement( &quot;SPAN&quot; );<br/>node.innerText = &quot;使用 innerText 属性&quot;;<br/>divUpdate.appendChild( node );<br/>}<br/></pre><h2><a name="dhtmlperf_topic4"></a>使用 DOM 添加单个元素</h2><p>如前所述，应用 HTML 文本的访问方法将导致调用 HTML 分析器，从而会降低性能。因此，使用 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createElement.asp">createElement</a>（英文）和 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertAdjacentElement.asp">insertAdjacentElement</a>（英文）方法添加元素比调用一次 <b>insertAdjacentHTML</b> 方法快。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 4：</b>调用 <b>createElement</b> 和 <b>insertAdjacentElement</b> 方法比调用 <b>insertAdjacentHTML</b> 方法快。</td>        </tr>    </tbody></table><br /></p><p>成批处理 DHTML 更新并调用一次 <b>insertAdjacentHTML</b> 方法可以提高性能，但是有时直接通过 DOM 创建元素效率更高。在下面的方案中，您可以尝试一下这两种方法并确定哪一种更快。</p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/tip4.asp">请显示</a></p><p><b>慢：</b></p><pre class="clsCode"> for (var i=0; i&lt;100; i++)<br/>{<br/>divUpdate.insertAdjacentHTML( &quot;beforeEnd&quot;, &quot;&lt;SPAN&gt; 使用 insertAdjacentHTML() &lt;/SPAN&gt;&quot; );<br/>}<br/></pre><p><b>快：</b></p><pre class="clsCode"> var node;<br/>for (var i=0; i&lt;100; i++)<br/>{<br/>node = document.createElement( &quot;SPAN&quot; );<br/>node.innerText = &quot; 使用 insertAdjacentElement() &quot;;<br/>divUpdate.insertAdjacentElement( &quot;beforeEnd&quot;, node );<br/>}<br/></pre><h2><a name="dhtmlperf_topic5"></a>扩展 SELECT 元素中的选项</h2><p>对于上一条使用 HTML 文本方法的规则来说，将大量 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/option.asp">OPTION</a>（英文）元素添加到 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/select.asp">SELECT</a>（英文）中的情况是一种例外。这时候，使用 <b>innerHTML</b> 属性比调用 <b>createElement</b> 方法访问选项集合效率更高。 </p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 5：</b>使用 <b>innerHTML</b> 将大量选项添加到 <b>SELECT</b> 元素中。</td>        </tr>    </tbody></table><br /></p><p>使用字符串连接操作来建立 <b>SELECT</b> 元素的 HTML 文本，然后使用此技巧设置 <b>innerHTML</b> 属性。对于数量特别大的选项，字符串连接操作也会影响性能。在此情况下，请建立一个数组并调用 Microsoft JScript&reg; <a href="http://msdn.microsoft.com/scripting/jscript/doc/jsmthjoin.htm">join</a>（英文）方法来执行 <b>OPTION</b> 元素 HTML 文本的最终连接。</p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/tip5.asp">请显示</a></p><p><b>慢：</b></p><pre class="clsCode"> var opt;<br/>divUpdate.innerHTML = &quot;&lt;SELECT ID=&#39;selUpdate&#39;&gt;&lt;/SELECT&gt;&quot;;<br/>for (var i=0; i&lt;1000; i++)<br/>{<br/>opt = document.createElement( &quot;OPTION&quot; );<br/>selUpdate.options.add( opt );<br/>opt.innerText = &quot;第 &quot; + i + &quot; 项&quot;;<br/>}<br/></pre><p><b>快：</b></p><pre class="clsCode"> var str=&quot;&lt;SELECT ID=&#39;selUpdate&#39;&gt;&quot;;<br/>for (var i=0; i&lt;1000; i++)<br/>{<br/>str += &quot;&lt;OPTION&gt;第 &quot; + i + &quot; 项&lt;/OPTION&gt;&quot;;<br/>}<br/>str += &quot;&lt;/SELECT&gt;&quot;;<br/>divUpdate.innerHTML = str;<br/></pre><p><b>更快：</b></p><pre class="clsCode"> var arr = new Array(1000);<br/>for (var i=0; i&lt;1000; i++)<br/>{<br/>arr[i] = &quot;&lt;OPTION&gt;第 &quot; + i + &quot; 项&lt;/OPTION&gt;&quot;;<br/>}<br/>divUpdate.innerHTML = &quot;&lt;SELECT ID=&#39;selUpdate&#39;&gt;&quot; + arr.join() + &quot;&lt;/SELECT&gt;&quot;;<br/></pre><h2><a name="dhtmlperf_topic6"></a>用 DOM 更新表</h2><p>使用 DOM 方法插入表的行和单元格比使用 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertRow.asp">insertRow</a>（英文）和 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertCell.asp">insertCell</a>（英文）方法（DHTML table 对象模型的一部分）效率更高。尤其在创建大的表时，效率上的差别更加明显。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 6：</b>使用 DOM 方法建立大表。</td>        </tr>    </tbody></table><br /></p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/tip6.asp">请显示</a></p><p><b>慢：</b></p><pre class="clsCode"> var row;<br/>var cell;<br/>for (var i=0; i&lt;100; i++)<br/>{<br/>row = tblUpdate.insertRow();<br/>for (var j=0; j&lt;10; j++)<br/>{<br/>cell = row.insertCell();<br/>cell.innerText = &quot;第 &quot; + i + &quot; 行，第 &quot; + j + &quot; 单元格&quot;;<br/>}<br/>}<br/></pre><p><b>快：</b></p><pre class="clsCode"> var row;<br/>var cell;<br/>var tbody = tblUpdate.childNodes[0];<br/>tblUpdate.appendChild( tbody );<br/>for (var i=0; i&lt;100; i++)<br/>{<br/>row = document.createElement( &quot;TR&quot; );<br/>tbody.appendChild( row );<br/>for (var j=0; j&lt;10; j++)<br/>{<br/>cell = document.createElement( &quot;TD&quot; );<br/>row.appendChild( cell );<br/>cell.innerText = &quot;第 &quot; + i + &quot; 行，第 &quot; + j + &quot; 单元格&quot;;<br/>}<br/>}<br/></pre><h2><a name="dhtmlperf_topic7"></a>编写一次，使用多次</h2><p>如果您的 Web 站点使用脚本来执行一些常用操作，可以考虑将这些功能放到独立的文件中，以便可以由多个 Web 页面重复使用。这样做，不仅可以改善代码的维护性，而且使该脚本文件保留在浏览器的缓存中，从而只需要在用户访问站点时向本地下载一次。将常用的样式规则放在独立的文件中也可以得到同样的好处。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 7：</b>通过将常用代码放到行为或独立文件中来重用脚本。</td>        </tr>    </tbody></table><br /></p><p>要更好地利用脚本重用功能，请将常用的脚本操作放到 DHTML 附加代码或元素<a href="http://msdn.microsoft.com/workshop/author/behaviors/overview.asp">行为</a>（英文）中。行为提供了一个有效的方法，用于重用脚本和建立从 HTML 访问的组件，并使您可用自己的对象、方法、属性和事件来扩展 DHTML 对象模型。对于未使用 <a href="http://msdn.microsoft.com/workshop/author/behaviors/overview/viewlink_ovw.asp">viewlink</a>（英文）功能的行为，可以考虑使用 Internet Explorer 5.5 中的 <a href="http://msdn.microsoft.com/workshop/author/behaviors/overview/elementb_ovw.asp#LightweightHTCs">lightweight</a>（英文）行为特性进行更有效的代码封装。另外，如果您的脚本代码在一个 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/script.asp">SCRIPT</a>（英文）块中，会获得更高的性能。</p><h2><a name="dhtmlperf_topic8"></a>请勿过多使用动态属性</h2><p><a href="http://msdn.microsoft.com/workshop/author/dhtml/overview/recalc.asp">动态属性</a>（英文）为 Web 作者提供了一种将表达式用作属性值的方法。表达式在运行时计算，其结果值将应用于属性。这是一个强大的特性。此特性可用于减少页面上的脚本数量，但是因为必须定时重算表达式，而且该表达式经常与其他属性值相关，所以它会对性能带来消极的影响。这种情况对定位属性尤其明显。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 8：</b>限制使用动态属性。</td>        </tr>    </tbody></table><br /></p><h2><a name="dhtmlperf_topic9"></a>数据绑定很有效</h2><p><a href="http://msdn.microsoft.com/workshop/author/databind/data_binding.asp">数据绑定</a>（英文）是一个强大的功能，它使您可以将数据库查询的结果或 <a href="http://msdn.microsoft.com/xml/tutorial/author_island.asp">XML 数据岛</a>（英文）的内容，绑定至 Web 页面上的 HTML 元素。您无需返回服务器提取数据，就可以提供数据排序和过滤功能，以及不同的数据视图。设想一个 Web 页面可以将公司的数据显示为折线图、条形图或饼图，还具有将数据按办公室、产品或销售阶段排序的按钮，而且所有这些功能只需要访问一次服务器就能实现。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 9：</b>使用数据绑定来提供丰富的客户端数据视图。</td>        </tr>    </tbody></table><br /></p><p>有关数据绑定的详细信息，请参见以下文章： </p><ul>    <li><a href="http://msdn.microsoft.com/workshop/author/databind/data_binding.asp">数据绑定概述</a>（英文）<br /></li>    <li><a href="http://msdn.microsoft.com/workshop/author/databind/dude1103.asp">绑定页面数据</a>（英文）<br /></li>    <li><a href="http://msdn.microsoft.com/workshop/author/databind/dude010499.asp">倾斜的、平均的和事实上的数据绑定</a>（英文） </li></ul><h2><a name="dhtmlperf_topic10"></a>不要在 document 对象中设置 expando 属性</h2><p><a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/expando.asp">expando</a>（英文）属性可以添加至任何对象。此属性非常有用，它可以存储当前 Wed 页面内的信息，并提供了另一种扩展 DHTML 对象模型的方法。例如，您可以给 DHTML 元素指定一个 <i>clicked</i> 属性，用此属性提示用户已经单击了哪一个元素。在引发事件时，也可以使用 <b>expando</b> 属性，向事件处理函数提供更多的上下文信息。无论您如何使用 <b>expando</b> 属性，切记不要在 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_document.asp">document</a>（英文）对象上设置它们。如果您这样做，则当您访问该属性时，文档必须执行额外的重算操作。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 10：</b>在 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_window.asp">window</a>（英文）对象上设置 <b>expando</b> 属性。</td>        </tr>    </tbody></table><br /></p><p><a href="http://www.microsoft.com/china/MSDN/library/archives/MSDNonline/features/articles/tip10.asp">请显示</a></p><p><b>慢：</b></p><pre class="clsCode">for (var i=0; i&lt;1000; i++)<br/>{<br/>var tmp;<br/>window.document.myProperty = &quot;第 &quot; + i + &quot; 项&quot;;<br/>tmp = window.document.myProperty;<br/>}<br/></pre><p><b>快：</b></p><pre class="clsCode">for (var i=0; i&lt;1000; i++)<br/>{<br/>var tmp;<br/>window.myProperty = &quot;第 &quot; + i + &quot; 项&quot;;<br/>tmp = window.myProperty;<br/>}<br/></pre><h2><a name="dhtmlperf_topic10a"></a>避免切换类和样式规则</h2><p>切换类和样式规则是一种代价非常高的操作，需要重新计算并调整整个文档的布局。如果您的 Web 站点使用样式表来提供内容的备用视图，可以考虑直接修改要更改的元素的 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_style.asp">style</a>（英文）对象，而不是修改元素的 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/className.asp">className</a>（英文）属性或与类关联的 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_stylesheet.asp">styleSheet</a>（英文）对象。 </p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 11：</b>在更改内容的外观时，直接修改 <b>style</b> 对象。</td>        </tr>    </tbody></table><br /></p><h2><a name="dhtmlperf_topic11"></a>查找父项之前，先折叠文本范围</h2><p><a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_textrange.asp">TextRange</a>（英文）对象表示用户选定或从 HTML 元素中检索的一个文本区域，例如 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/body.asp">BODY</a>（英文）。通过调用 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/parentelement_1.asp">parentElement</a>（英文）方法，可以标识文本范围的父项。对于复杂的文本范围，在调用 <b>parentElement</b> 方法之前，先调用 <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/collapse.asp">collapse</a>（英文）方法效率会更高。</p><p><table style="FONT-SIZE: 9pt" cols="1" rules="rows" width="500" border="1" frame="box">    <tbody>        <tr valign="top">            <td width="100%" bgcolor="#a6caf0"><b>技巧 12：</b>在访问 <b>parentElement</b> 方法之前，先折叠文本范围。</td>        </tr>    </tbody></table><br /></p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/47.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=47</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=47&amp;key=5451d1e4</trackback:ping></item><item><title>XHTML代码规范</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/41.html</link><pubDate>Thu, 18 Aug 2005 19:40:00 +0800</pubDate><guid>http://blog.hnce.net/post/41.html</guid><description><![CDATA[<h3><font size="1">XHTML规范如下：</font></h3><h3>1.所有的标记都必须要有一个相应的结束标记</h3><p>以前在HTML中，你可以打开许多标签，例如&lt;p&gt;和&lt;li&gt;而不一定写对应的&lt;/p&gt;和&lt;/li&gt;来关闭它们。但在XHTML中这是不合法的。XHTML要求有严谨的结构，所有标签必须关闭。如果是单独不成对的标签，在标签最后加一个&quot;/&quot;来关闭它。例如:</p><p><span class="code">&lt;br /&gt;</span><span class="code">&lt;img height=&quot;80&quot; alt=&quot;网页设计师&quot; src=&quot;../images/logo_w3cn_200x80.gif&quot; width=&quot;200&quot; /&gt;</span> <br /><br /></p><h3>2.所有标签的元素和属性的名字都必须使用小写</h3><p>与HTML不一样，XHTML对大小写是敏感的，&lt;title&gt;和&lt;TITLE&gt;是不同的标签。XHTML要求所有的标签和属性的名字都必须使用小写。例如：&lt;BODY&gt;必须写成&lt;body&gt; 。大小写夹杂也是不被认可的，通常dreamweaver自动生成的属性名字&quot;<i>onMouse</i>Over&quot;也必须修改成&quot;<i>onmouse</i>over&quot;。</p><h3>3.所有的XML标记都必须合理嵌套</h3><p>同样因为XHTML要求有严谨的结构，因此所有的嵌套都必须按顺序，以前我们这样写的代码：</p><p><span class="code">&lt;p&gt;&lt;b&gt;&lt;/p&gt;/b&gt;</span> </p><p>必须修改为：</p><p><span class="code">&lt;p&gt;&lt;b&gt;&lt;/b&gt;/p&gt;</span> </p><p>就是说，一层一层的嵌套必须是严格对称。</p><h3>4.所有的属性必须用引号&quot;&quot;括起来</h3><p>在HTML中，你可以不需要给属性值加引号，但是在XHTML中，它们必须被加引号。例如:</p><p><span class="code">&lt;height=80&gt;</span> </p><p>必须修改为：</p><p><span class="code">&lt;height=&quot;80&quot;&gt;</span> </p><p>特殊情况，你需要在属性值里使用双引号，你可以用&quot;，单引号可以使用&amp;apos;，例如：</p><p><span class="code">&lt;alt=&quot;say&amp;apos;hello&amp;apos;&quot;&gt;</span> </p><h3>5.把所有&lt;和&amp;特殊符号用编码表示</h3><ul>    <li>任何小于号（&lt;），不是标签的一部分，都必须被编码为<span class="code">&amp; l t ;</span> </li>    <li>任何大于号（&gt;），不是标签的一部分，都必须被编码为<span class="code">&amp; g t ;</span> </li>    <li>任何与号（&amp;），不是实体的一部分的，都必须被编码为<span class="code">&amp; a m p;</span> </li></ul><p>注：以上字符之间无空格。</p><h3>6.给所有属性赋一个值</h3><p>XHTML规定所有属性都必须有一个值，没有值的就重复本身。例如：</p><p><span class="code">&lt;td nowrap&gt;</span> <span class="code">&lt;input type=&quot;checkbox&quot; name=&quot;shirt&quot; <i>value</i>=&quot;medium&quot; checked&gt;</span> </p><p>必须修改为：</p><p><span class="code">&lt;td nowrap=&quot;nowrap&quot;&gt;</span> <span class="code">&lt;input type=&quot;checkbox&quot; name=&quot;shirt&quot; <i>value</i>=&quot;medium&quot; checked=&quot;checked&quot;&gt;</span> </p><h3>7.不要在注释内容中使&ldquo;--&rdquo;</h3><p>&ldquo;--&rdquo;只能发生在XHTML注释的开头和结束，也就是说，在内容中它们不再有效。例如下面的代码是无效的:</p><p><span class="code">&lt;!--这里是注释-----------这里是注释--&gt;</span> </p><p>用等号或者空格替换内部的虚线。</p><p><span class="code">&lt;!--这里是注释============这里是注释--&gt;</span> </p><p>以上这些规范有的看上去比较奇怪，但这一切都是为了使我们的代码有一个统一、唯一的标准，便于以后的数据再利用。</p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/41.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=41</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=41&amp;key=971524d2</trackback:ping></item><item><title>用CSS实现双色相间表格</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/40.html</link><pubDate>Thu, 18 Aug 2005 15:16:00 +0800</pubDate><guid>http://blog.hnce.net/post/40.html</guid><description><![CDATA[<p>具体代码<br /><br /><br />&lt;html&gt;<br />&lt;body&gt;<br />&lt;style&gt;&nbsp;<br />.DoubleColorTable&nbsp;tr{<br />&nbsp;background-color:expression(&quot;#FFFFFF,#EEEEEE&quot;.split(&quot;,&quot;)[rowIndex%2])<br />}&nbsp;<br />&lt;/style&gt;&nbsp;<br />&lt;table&nbsp;width=&quot;70%&quot;&nbsp;&nbsp;border=&quot;1&quot;&nbsp;cellpadding=&quot;0&quot;&nbsp;&nbsp;class=&quot;DoubleColorTable&quot;&gt;<br />&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;&nbsp;</p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/40.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=40</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=40&amp;key=e16a51bc</trackback:ping></item><item><title>有关表格边框的css语法整理</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/34.html</link><pubDate>Mon, 01 Aug 2005 17:02:00 +0800</pubDate><guid>http://blog.hnce.net/post/34.html</guid><description><![CDATA[<font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我们知道Dreamweaver在表格制作方面做得非常出色，但是在某些时候还是必须结合css才能达到一些特定效果，下面我们先把有关表格边框的css语法整理出来，然后另外介绍怎样用css美化表格的边框。</font><br/><p><font size="2">　　</font><font size="2"><font color="#ac0000"><strong>有关表格边框的css语法<br /><br /></strong></font><font color="#000000">　　具体内容包括：上边框宽度、右边框宽度、下边框宽度、左边框宽度、边框宽度、边框颜色、边框样式、上边框、下边框、左边框、右边框、边框、宽度、高度、有关标签等。</font></font></p><p><font size="2">　　 </font><font size="2"><strong>1.上边框宽度<br /></strong>　　语法: border-top-width: &lt;值&gt;</font></p><p><font size="2">　　允许值: thin | medium | thick | &lt;长度&gt;</font></p><p><font size="2">　　初始值: medium</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　上边框宽度属性用于指定一个元素上边框的宽度。值可以是三个关键字其中的一个，都不受字体大小或长度的影响，可以用于实现成比例的宽度。不允许使用负值。也可以用在上边框、边框的宽度或边框的属性略写。</font></p><p><font size="2">　　</font><font size="2"><strong>2.右边框宽度<br /><br /></strong>　　语法: border-right-width: &lt;值&gt;</font></p><p><font size="2">　　允许值: thin | medium | thick | &lt;长度&gt;</font></p><p><font size="2">　　初始值: medium</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　右边框宽度属性用于指定元素的右边框的宽度。值可以是三个关键字其中的一个，都不受字体大小或长度的影响，可以用于实现成比例的宽度。不允许使用负值。也可以用在右边框、边框的宽度或边框的属性略写。</font></p><p><font size="2">　　 </font><font size="2"><strong>3.下边框宽度<br /><br /></strong>　　语法: border-bottom-width: &lt;值&gt;</font></p><p><font size="2">　　允许值: thin | medium | thick | &lt;长度&gt;</font></p><p><font size="2">　　初始值: medium</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　下边框宽度属性用于指定元素的下边框的宽度。值可以是三个关键字其中的一个，都不受字体大小或长度的影响，可以用于实现成比例的宽度。不允许使用负值。也可以用在下边框、边框的宽度或边框的属性略写。</font></p><p><font size="2">　　 </font><font size="2"><strong>4.左边框宽度<br /><br /></strong>　　语法: border-left-width: &lt;值&gt;</font></p><p><font size="2">　　允许值: thin | medium | thick | &lt;长度&gt;</font></p><p><font size="2">　　初始值: medium</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　左边框宽度属性用于指定元素的左边框的宽度。值可以是三个关键字其中的一个，都不受字体大小或长度的影响，可以用于实现成比例的宽度。不允许使用负值。也可以用在左边框、边框的宽度或边框的属性略写。</font></p><p><font size="2">　　</font><font size="2"><strong>5.边框宽度<br /></strong><br />　　语法: border-width: &lt;值&gt;</font></p><p><font size="2">　　允许值: [ thin | medium | thick | &lt;长度&gt; ]{1,4}</font></p><p><font size="2">　　初始值: 未定义</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　边框宽度属性用一到四个值来设置元素的边界，值是一个关键字或长度。不允许使用负值长度。如果四个值都给出了，它们分别应用于上、右、下和左边框的式样。如果给出一个值，它将被运用到各边上。如果两个或三个值给出了，省略了的值与对边相等。 这个属性是上边框宽度、右边框宽度、下边框宽度和左边框宽度属性的略写。也可以使用略写的边框属性。</font></p><p><font size="2">　　</font><font size="2"><strong>6.边框颜色<br /></strong><br />　　语法: border-color: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;颜色&gt;{1,4}</font></p><p><font size="2">　　初始值: 颜色属性的值</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　边框颜色属性设置一个元素的边框颜色。可以使用一到四个关键字。如果四个值都给出了，它们分别应用于上、右、下和左边框的式样。如果给出一个值，它将被运用到各边上。如果两个或三个值给出了，省略了的值与对边相等。也可以使用略写的边框属性。</font></p><p><font size="2">　　</font><font size="2"><strong>7.边框样式<br /></strong><br />　　语法: border-style: &lt;值&gt;</font></p><p><font size="2">　　允许值: [ none | dotted | dashed | solid | double | groove | ridge | inset | outset ]{1,4}</font></p><p><font size="2">　　初始值: none</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　边框样式属性用于设置一个元素边框的样式。这个属性必须用于指定可见的边框。可以使用一到四个关键字。如果四个值都给出了，它们分别应用于上、右、下和左边框的式样。如果给出一个值，它将被运用到各边上。如果两个或三个值给出了，省略了的值与对边相等。也可以使用<strong>略写的边框属性</strong>。<br /><br />　　none：无样式；<br />　　dotted：点线；<br />　　dashed：虚线；<br />　　solid：实线；<br />　　double：双线；<br />　　groove：槽线；<br />　　ridge：脊线；<br />　　inset：内凹；<br />　　outset：外凸。</font></p><p><font size="2"><strong>8.上边框<br /><br /></strong>　　语法: border-top: &lt;值&gt; </font></p><p><font size="2"></font></p><p><font size="2">　　允许值: &lt;上边框宽度&gt; || &lt;边框式样&gt; || &lt;颜色&gt;</font></p><p><font size="2">　　初始值: 未定义</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　上边框属性是一个用于设置一个元素上边框的宽度、式样和颜色的略写。<strong>注意</strong>只能给出一个边框式样。也可以使用略写的边框属性。</font></p><p><font size="2">　　</font><font size="2"><strong>9.右边框<br /><br /></strong>　　语法: border-right: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;右边框宽度&gt; || &lt;边框式样&gt; || &lt;颜色&gt;</font></p><p><font size="2">　　初始值: 未定义</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　右边框属性是一个用于设置一个元素右边框的宽度、式样、和颜色的略写。<strong>注意</strong>只能给出一个边框式样。也可以使用略写的边框属性。　　&nbsp;</font></p><p><font size="2">　　</font><font size="2"><strong>10.下边框<br /><br /></strong>　　语法: border-bottom: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;下边框宽度&gt; || &lt;边框式样&gt; || &lt;颜色&gt;</font></p><p><font size="2">　　初始值: 未定义</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　下边框属性是一个用于设置一个元素的下边框的宽度、式样和颜色的略写。<strong>注意</strong>只能给出一个边框式样。也可以使用略写的边框属性。</font></p><p><font size="2">　　</font><font size="2"><strong>11.左边框<br /><br /></strong>　　语法: border-left: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;左边框宽度&gt; || &lt;边框式样&gt; || &lt;颜色&gt;</font></p><p><font size="2">　　初始值: 未定义</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　左边框属性是一个用于设置一个元素左边框的宽度、式样和颜色的略写。<strong>注意</strong>只能给出一个边框式样。也可以使用略写的边框属性。</font></p><p><font size="2">　　&nbsp;</font><font size="2"><strong>12.边框<br /><br /></strong>　　语法: border: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;边框宽度&gt; || &lt;边框式样&gt; || &lt;颜色&gt;</font></p><p><font size="2">　　初始值: 未定义</font></p><p><font size="2">　　适用于: 所有对象</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　边框属性是一个用于设置一个元素边框的宽度、式样和颜色的略写。</font></p><p><font size="2">　　边框声明的例子包括：</font></p><p><font size="2">　　H2 { border: groove 3em }<br />　　A:link { border: solid blue }<br />　　A:visited { border: thin dotted #800080 }<br />　　A:active { border: thick double red }<br /><br />　　边框属性只能设置四种边框；只能给出一组边框的宽度和式样。为了给出一个元素的四种边框的不同的值，网页制作者必须用一个或更多的属性，如：上边框、右边框、下边框、左边框、边框颜色、边框宽度、边框式样、上边框宽度、右边框宽度、下边框宽度或左边框宽度。 </font></p><p><font size="2">　　</font><font size="2"><strong>13.宽度<br /></strong><br />　　语法: width: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;长度&gt; | &lt;百分比&gt; | auto</font></p><p><font size="2">　　初始值: auto</font></p><p><font size="2">　　适用于: 块级和替换元素</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　宽度属性的初始值为&ldquo;auto&rdquo;，即为该元素的原有宽度(有就是元素自己的宽度)。百分比参考上级元素的宽度。不允许使用负的长度值。</font></p><p><font size="2">　　</font><font size="2"><strong>14.高度<br /></strong><br />　　语法: height: &lt;值&gt;</font></p><p><font size="2">　　允许值: &lt;长度&gt; | auto</font></p><p><font size="2">　　初始值: auto</font></p><p><font size="2">　　适用于: 块级和替换元素</font></p><p><font size="2">　　向下兼容: 否</font></p><p><font size="2">　　高度属性的初始值为&ldquo;auto&rdquo;，即为该元素的原有高度(有就是元素自己的高度，)。百分比参考上级元素的宽度。不允许使用负的长度值。</font></p><p><font size="2">　　</font><font size="2"><strong>15.有关标签<br /><br /></strong>　　table：表格标签，对整个表格样式的定义要放在table中；<br />　　td：单元格标签，对单元格样式的定义要放在td中。</font></p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/34.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=34</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=34&amp;key=ba2deb64</trackback:ping></item><item><title>网页中有关表格的处理</title><author>a@b.com (slick)</author><link>http://blog.hnce.net/post/31.html</link><pubDate>Sun, 31 Jul 2005 10:37:00 +0800</pubDate><guid>http://blog.hnce.net/post/31.html</guid><description><![CDATA[<p><font color="#0000ff">表格复选、复选变色、以及行的间隔行</font> <br />用Hotmail的时候注意下，就是这个效果 <br />以下内容为程序代码：</p><p>&lt;style&nbsp;type=&quot;text/css&quot;&gt; <br />&lt;!-- <br />.row&nbsp;{BACKGROUND-COLOR:&nbsp;expression(rowIndex%2==1?'':'#F5F5F5')} <br />Body&nbsp;{FONT-SIZE:&nbsp;12px;&nbsp;FONT-FAMILY:&nbsp;Arial,Verdana,sans-serif;LINE-HEIGHT:&nbsp;150%;} <br />Td&nbsp;{FONT-SIZE:&nbsp;12px;&nbsp;FONT-FAMILY:&nbsp;Arial,Verdana,sans-serif;LINE-HEIGHT:&nbsp;150%;} <br />.tb&nbsp;{border-collapse:&nbsp;collapse} <br />--&gt; <br />&lt;/style&gt; <br />&lt;script&nbsp;language=&quot;JavaScript&quot;&nbsp;type=&quot;text/JavaScript&quot;&gt; <br />//复选 <br />function&nbsp;selectAll(chk) <br />{&nbsp;&nbsp;&nbsp;&nbsp; <br />var&nbsp;chk&nbsp;=&nbsp;document.form1.chkAll.checked; <br />for&nbsp;(i=0;i&lt;document.all.length;i++)&nbsp;{ <br />if&nbsp;(document.all[i].name==&quot;id[]&quot;)&nbsp;{ <br />document.all[i].checked=chk; <br />chkRow(document.all[i]); <br />}}} <br /><br /><br />//复选后单元格变色 <br />function&nbsp;chkRow(obj){ <br />var&nbsp;r&nbsp;=&nbsp;obj.parentElement.parentElement; <br />if(obj.checked){&nbsp;r.style.backgroundColor=&quot;#E6E9F2&quot;;} <br />else&nbsp;{if(r.rowIndex%2==1)r.style.backgroundColor=&quot;&quot;;else&nbsp;r.style.backgroundColor=&quot;#F5F5F5&quot;;} <br />} <br />&lt;/script&gt; <br />&lt;table&nbsp;width=&quot;50%&quot;&nbsp;&nbsp;border=&quot;1&quot;&nbsp;cellpadding=&quot;3&quot;&nbsp;cellspacing=&quot;0&quot;&nbsp;bordercolor=&quot;#333333&quot;&nbsp;class=&quot;tb&quot;&gt; <br />&lt;form&nbsp;name=&quot;form1&quot;&nbsp;method=&quot;post&quot;&nbsp;action=&quot;&quot;&gt; <br />&nbsp;&nbsp;&lt;tr&nbsp;class=&quot;row&quot;&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;width=&quot;5%&quot;&gt;&nbsp;&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;width=&quot;33%&quot;&nbsp;align=&quot;center&quot;&gt;&lt;strong&gt;论坛名称&lt;/strong&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;width=&quot;62%&quot;&nbsp;align=&quot;center&quot;&gt;&lt;strong&gt;网&nbsp;址&lt;/strong&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&lt;/tr&gt; <br />&nbsp;&nbsp;&lt;tr&nbsp;class=&quot;row&quot;&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;&lt;input&nbsp;type=&quot;checkbox&quot;&nbsp;name=&quot;id[]&quot;&nbsp;value=&quot;1&quot;&nbsp;onclick=&quot;javascript:chkRow(this);&quot;&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;织梦乱弹&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;&lt;a&nbsp;href=&quot;http://www.it365cn.com/bbs&quot;&nbsp;target=&quot;_blank&quot;&gt;http://www.it365cn.com/bbs&lt;/a&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&lt;/tr&gt; <br />&nbsp;&nbsp;&lt;tr&nbsp;class=&quot;row&quot;&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;&lt;input&nbsp;type=&quot;checkbox&quot;&nbsp;name=&quot;id[]&quot;&nbsp;value=&quot;1&quot;&nbsp;onclick=&quot;javascript:chkRow(this);&quot;&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;经典论坛&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;&lt;a&nbsp;href=&quot;http://www.blueidea.com/bbs&quot;&nbsp;target=&quot;_blank&quot;&gt;http://www.blueidea.com/bbs&lt;/a&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&lt;/tr&gt; <br />&nbsp;&nbsp;&lt;tr&nbsp;class=&quot;row&quot;&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;&lt;input&nbsp;type=&quot;checkbox&quot;&nbsp;name=&quot;id[]&quot;&nbsp;value=&quot;1&quot;&nbsp;onclick=&quot;javascript:chkRow(this);&quot;&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;点燃灵感&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=&quot;center&quot;&gt;&lt;a&nbsp;href=&quot;http://www.fwcn.com/bbs&quot;&nbsp;target=&quot;_blank&quot;&gt;http://www.fwcn.com/bbs&lt;/a&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&lt;/tr&gt; <br />&nbsp;&nbsp;&lt;tr&nbsp;class=&quot;row&quot;&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;colspan=&quot;3&quot;&gt;&lt;input&nbsp;type=&quot;checkbox&quot;&nbsp;name=&quot;chkAll&quot;&nbsp;title=&quot;全选/取消&quot;&nbsp;onclick=&quot;selectAll()&quot;&gt;&nbsp;&lt;strong&gt;全选/取消&lt;/strong&gt;&lt;/td&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt; <br />&lt;/form&gt;&nbsp;&nbsp; <br />&lt;/table&gt; <br /></p><p><font color="#0000ff">限制表格的大小</font> <br /><br />style=&quot;&nbsp;table-layout:fixed;word-break:break-all&quot;&nbsp;&nbsp;'關鍵就是這句了 <br />如果是只要限制td大小&nbsp;可以 <br /><br /><br />无论大图还是文字，一律限制。 <br />以下内容为程序代码：</p><p>&lt;table&nbsp;&nbsp;&nbsp;&nbsp;align=center&nbsp;&nbsp;&nbsp;&nbsp;width=200&nbsp;&nbsp;&nbsp;&nbsp;height=100&nbsp;&nbsp;&nbsp;&nbsp;bgcolor=#f3f3f3&nbsp;&nbsp;style=&quot;filter:progid:DXImageTransform.Microsoft.Shadow(Color=#333333,Direction=120,strength=5)&quot;&nbsp;style=&quot;table-layout:fixed;word-break:break-all&quot;&nbsp;&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;center&gt;&lt;img&nbsp;&nbsp;src=&quot;http://www.cnbruce.com/images/cnrose/mi.jpg&quot;&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&nbsp; <br />cnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbrucecnbruce <br />&lt;/td&gt;&lt;/tr&gt; <br />&lt;/table&gt; <br /></p><p><font color="#0000ff">表格行换色</font> (表格换行换色)</p><p>&lt;style&gt; <br />#oTable&nbsp;tr&nbsp;{alternateColor:expression(bgColor=rowIndex%2==0?'#cccccc':'#efefef')} <br />&lt;/style&gt; <br />&lt;table&nbsp;width=500&nbsp;height=100&nbsp;border=1&nbsp;ID=&quot;oTable&quot;&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;tr&gt; <br />&lt;td&gt;&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;/table&gt; <br /></p><p>立体表格</p><p>&lt;table&nbsp; border=1 cellspacing=0&nbsp; width=100% bordercolorlight=#333333 bordercolordark=#efefef&gt;<br />&lt;tr bgcolor=#cccccc&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;/tr&gt;<br />&lt;tr bgcolor=#cccccc&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;td&gt;cnbruce&lt;/td&gt;<br />&lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;center&gt;表格边线为1，间隔为0，左上为#333333，右下为#efefef,行背景色为#cccccc<br /></p><p>表格的边框不断在闪&nbsp;<br />&lt;table border=&quot;0&quot; width=&quot;280&quot; id=&quot;myexample&quot; style=&quot;border:1px solid red&quot;&gt; <br />&lt;tr&gt; <br />&lt;td&gt;cnbruce cnbruce cnbruce cnbruce cnbruce cnbruce&lt;/td&gt; <br />&lt;/tr&gt; <br />&lt;/table&gt; <br />&lt;script language=&quot;JavaScript1.2&quot;&gt;<br />&lt;!-- <br />function flashit(){ <br />if (!document.all) <br />return <br />if (myexample.style.borderColor==&quot;blue&quot;) <br />myexample.style.borderColor=&quot;red&quot; <br />else <br />myexample.style.borderColor=&quot;blue&quot; <br />} <br />setInterval(&quot;flashit()&quot;, 500) <br />//--&gt; <br />&lt;/script&gt; <br /></p><p>虚线表格</p><p>&lt;style type=&quot;text/css&quot;&gt;<br />.tb{BORDER-BOTTOM: #000000 1px dotted;BORDER-top: #000000 1px dotted;BORDER-LEFT: #000000 1px dotted;BORDER-RIGHT: #000000 1px dotted;}<br />&lt;/style&gt;<br />&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;<br />&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp; &lt;td class=&quot;tb&quot;&gt;&lt;center&gt;www.cnbruce.com&lt;/td&gt;<br />&nbsp; &lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;p&gt;<br />虚线直线1<br />&lt;hr size=1 style=&quot;border:1px dotted #001403;&quot;&gt;<br />虚线直线2<br />&lt;p size=1 style=&quot;border:1px dotted #001403;&quot;&gt;<br /></p><p>分类型表格</p><p>&lt;fieldset&gt;<br />&lt;legend&gt;item&lt;/legend&gt;<br />content<br />&lt;/fieldset&gt;<br /></p><p>变色的单元格1，通过a:hover做.<br />&lt;style&gt;<br />a:link,a:visited,a:hover<br />{width:100%;text-decoration:none;font-family:verdana;font-size:10px;color:white}<br />a:hover{background:#0099ff;color:black}<br />td{background:#3366cc;color:white;padding:0px}<br />&lt;/style&gt;</p><p>&lt;TABLE width=100% cellspacing=1 bgcolor=black &gt;<br />&lt;TR&gt;<br />&nbsp;&nbsp;&nbsp; &lt;TD&gt;&lt;a href=&quot;#&quot;&gt;CNBruce<br />&nbsp;&nbsp;&nbsp; &lt;TD&gt;&lt;a href=&quot;#&quot;&gt;.com<br />&lt;TR&gt;<br />&nbsp;&nbsp;&nbsp; &lt;TD&gt;&lt;a href=&quot;#&quot;&gt;CNBruce<br />&nbsp;&nbsp;&nbsp; &lt;TD&gt;&lt;a href=&quot;#&quot;&gt;.com<br /></p><p>变色的单元格2，已经做成了CSS，注意还有透明效果。<br /></p><p>&lt;style type=&quot;text/css&quot;&gt;<br />.aa<br />{ background-color:#0000ff; color:#ff0000;filter: alpha(opacity=50)}<br />.bb&nbsp;&nbsp;&nbsp; <br />{ background-color:#3366cc; color:#ffffff}<br />&lt;/style&gt;</p><p>&lt;table&nbsp; width=&quot;100%&quot;&gt;<br />&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp; &lt;td&nbsp; onmouseover=&quot;this.className='aa'&quot; onmouseout=&quot;this.className='bb'&quot; class=&quot;bb&quot;&gt;&lt;center&gt;&lt;b&gt;cnbruce&lt;/td&gt;<br />&nbsp;&nbsp; &lt;/tr&gt;<br />&lt;/table&gt;<br /></p><p>变色的单元格3，通过mouse事件做.有点微软的味道。<br /></p><p>&lt;table width=&quot;100%&quot; border=&quot;1&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; bordercolor=&quot;#efefef&quot; bgcolor=&quot;#efefef&quot;&gt;<br />&nbsp; &lt;tr&gt; <br />&nbsp;&nbsp;&nbsp; &lt;td onMouseOut=&quot;this.bgColor='#efefef';this.borderColor='#efefef'&quot;; onMouseOver=&quot;this.bgColor='#cccccc'; this.borderColor='#000033'&quot;&gt;&lt;div align=&quot;left&quot;&gt;cnbruce&lt;/div&gt;&lt;/td&gt;<br />&nbsp; &lt;/tr&gt;<br />&nbsp; &lt;tr&gt; <br />&nbsp;&nbsp;&nbsp; &lt;td onMouseOut=&quot;this.bgColor='#efefef';this.borderColor='#efefef'&quot;; onMouseOver=&quot;this.bgColor='#cccccc'; this.borderColor='#000033'&quot;&gt;cnbruce&lt;/td&gt;<br />&nbsp; &lt;/tr&gt;<br />&lt;/table&gt;<br /></p><p>表格边框显示外阴影<br /></p><p>&lt;table&nbsp; align=center&nbsp; width=200&nbsp; height=100&nbsp; bgcolor=#f3f3f3 style=&quot;filter:progid:DXImageTransform.Microsoft.Shadow(Color=#333333,Direction=120,strength=5)&quot;&gt;<br />&lt;tr&gt;<br />&lt;td&gt;&lt;center&gt;www.cnbruce.com&lt;/td&gt;<br />&lt;/tr&gt;<br />&lt;/table&gt;<br /></p><p>VML做圆脚表格<br /></p><p>&lt;html xmlns:v&gt;<br />&lt;style&gt;<br />v\:*{behavior:url(#default#VML)}<br />&lt;/style&gt;<br />&lt;body&gt;<br />&nbsp;&nbsp; &lt;v:RoundRect style=&quot;position:relative;width:150;height:240px&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;v:shadow on=&quot;T&quot; type=&quot;single&quot; color=&quot;#b3b3b3&quot; offset=&quot;3px,3px&quot;/&gt;<br />&nbsp;&nbsp;&nbsp; &lt;v:TextBox style=&quot;font-size:10.2pt;&quot;&gt;VML&lt;/v:TextBox&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/v:RoundRect&gt; <br />&lt;/body&gt;<br />&lt;/html&gt;<br /></p><p>根据单元格内容加亮<br /></p><p>&lt;table&nbsp; border=&quot;1&quot;&nbsp; cellspacing=&quot;0&quot;&nbsp; width=&quot;400&quot;&nbsp; cellpadding=&quot;0&quot;&nbsp; id=&quot;table1&quot;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;12&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;34&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;56&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;78&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;90&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;abc&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;def&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;ghj&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;lop&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;dry&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;!@#&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;_(*&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;#$%&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;^$#&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&nbsp; width=&quot;80&quot;&gt;WWW&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/table&gt;</p><p>&lt;SCRIPT&gt;<br />var&nbsp; ids;<br />var&nbsp; idstext;<br />function&nbsp; hightlight_td(){<br />var&nbsp; text=txt.value;<br />TDs=document.all.table1.all.tags(&quot;TD&quot;)<br />//使用iframe时:<br />//TDs=iframe的name.document.all.table1.all.tags(&quot;TD&quot;)<br />&nbsp;&nbsp;&nbsp; if&nbsp; (text!=&quot;&quot;)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for&nbsp; (var&nbsp; i&nbsp; =&nbsp; 0;&nbsp; i&nbsp; &lt;&nbsp; TDs.length;&nbsp; i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj=TDs[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idstext=obj.innerText;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idnum=idstext.indexOf(text);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp; (idnum!=-1)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj.style.background=&quot;red&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj.style.background=&quot;#FFFFFF&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;没有输入&quot;);<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&lt;/SCRIPT&gt;<br />&lt;p&nbsp; align=&quot;center&quot;&gt;&lt;input&nbsp; type=&quot;text&quot;&nbsp; name=&quot;txt&quot;&nbsp; value=&quot;&quot;&gt;&lt;input&nbsp; type=&quot;button&quot;&nbsp; value=&quot;请输入要查的字符串.&quot;&nbsp; onClick=&quot;hightlight_td();&quot;&gt;&lt;/p&gt;<br /></p><p>单击表格换色</p><p>&lt;script&gt;<br />function bgChange(obj){<br />obj.bgColor=obj.bgColor==&quot;&quot;?&quot;#0099ff&quot;:&quot;&quot;;<br />}<br />&lt;/script&gt;<br />&lt;table width=&quot;80%&quot; border=&quot;1&quot;&gt;<br />&lt;tr onclick=&quot;bgChange(this)&quot;&gt;&lt;td&gt;a&lt;/td&gt;&lt;td&gt;a&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr onclick=&quot;bgChange(this)&quot;&gt;&lt;td&gt;a&lt;/td&gt;&lt;td&gt;a&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr onclick=&quot;bgChange(this)&quot;&gt;&lt;td&gt;a&lt;/td&gt;&lt;td&gt;a&lt;/td&gt;&lt;/tr&gt;<br />&lt;/table&gt;<br /></p><p>&nbsp;</p><p>&nbsp;</p>]]></description><category>HTML/CSS</category><comments>http://blog.hnce.net/post/31.html#comment</comments><wfw:comment>http://blog.hnce.net/</wfw:comment><wfw:commentRss>http://blog.hnce.net/feed.asp?cmt=31</wfw:commentRss><trackback:ping>http://blog.hnce.net/cmd.asp?act=tb&amp;id=31&amp;key=8abd7e20</trackback:ping></item></channel></rss>
