<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>张经纬的博客 &#187; CSS</title>
	<atom:link href="http://www.zhangjingwei.com/archives/category/web-developer/css-web-developer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zhangjingwei.com</link>
	<description>中隐留司官</description>
	<lastBuildDate>Wed, 08 Sep 2010 17:36:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CSS3 的显示与隐藏</title>
		<link>http://www.zhangjingwei.com/archives/css3-show-and-hide/</link>
		<comments>http://www.zhangjingwei.com/archives/css3-show-and-hide/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 04:38:24 +0000</pubDate>
		<dc:creator>张经纬</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.zhangjingwei.com/?p=1480</guid>
		<description><![CDATA[演示地址：http://www.zhangjingwei.com/demo/css-menu.html &#60; !DOCTYPE html&#62; &#60;head&#62; &#60;title&#62;menu mockup&#60;/title&#62; &#60;style type=&#34;text/css&#34;&#62; .show {display: none; } .hide:focus + .show {display: inline; } .hide:focus { display: none; } .hide:focus ~ #list { display:none; } @media print { .hide, .show { display: none; } } &#60;/style&#62; &#60;/head&#62; &#60;body&#62; &#60;p&#62;Here's a list&#60;/p&#62; &#60;div&#62; &#60;a href=&#34;#&#34; class=&#34;hide&#34;&#62;[hide]&#60;/a&#62; &#60;a href=&#34;#&#34; class=&#34;show&#34;&#62;[show]&#60;/a&#62; &#60;ol id=&#34;list&#34;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>演示地址：<a href="http://www.zhangjingwei.com/demo/css-menu.html">http://www.zhangjingwei.com/demo/css-menu.html</a></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html&gt;
&lt;head&gt;
   &lt;title&gt;menu mockup&lt;/title&gt;
   &lt;style type=&quot;text/css&quot;&gt;
      .show {display: none; }
      .hide:focus + .show {display: inline; }
      .hide:focus { display: none; }
      .hide:focus ~ #list { display:none; }
      @media print { .hide, .show { display: none; } }
   &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
   &lt;p&gt;Here's a list&lt;/p&gt;
      &lt;div&gt;
         &lt;a href=&quot;#&quot; class=&quot;hide&quot;&gt;[hide]&lt;/a&gt;
         &lt;a href=&quot;#&quot; class=&quot;show&quot;&gt;[show]&lt;/a&gt;
         &lt;ol id=&quot;list&quot;&gt;
            &lt;li&gt;item 1&lt;/li&gt;
            &lt;li&gt;item 2&lt;/li&gt;
            &lt;li&gt;item 3&lt;/li&gt;
         &lt;/ol&gt;
      &lt;/div&gt;
   &lt;p&gt;How about that?&lt;/p&gt;
&lt;/body&gt;</pre></div></div>




加入书签:


	<a rel="nofollow" class="thickbox" href="http://shuqian.qq.com/post?jumpback=1&title=CSS3%20%E7%9A%84%E6%98%BE%E7%A4%BA%E4%B8%8E%E9%9A%90%E8%97%8F&uri=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss3-show-and-hide%2F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss3-show-and-hide%2F&title=CSS3%20%E7%9A%84%E6%98%BE%E7%A4%BA%E4%B8%8E%E9%9A%90%E8%97%8F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss3-show-and-hide%2F&title=CSS3%20%E7%9A%84%E6%98%BE%E7%A4%BA%E4%B8%8E%E9%9A%90%E8%97%8F&n=1?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.haohaoreport.com/submit.php?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss3-show-and-hide%2F&amp;title=CSS3%20%E7%9A%84%E6%98%BE%E7%A4%BA%E4%B8%8E%E9%9A%90%E8%97%8F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/haohao.png" title="Haohao" alt="Haohao" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.zhangjingwei.com/feed/?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS3%20%E7%9A%84%E6%98%BE%E7%A4%BA%E4%B8%8E%E9%9A%90%E8%97%8F&amp;body=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss3-show-and-hide%2F" title="email"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.zhangjingwei.com/archives/css3-show-and-hide/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rel与CSS的联合使用</title>
		<link>http://www.zhangjingwei.com/archives/rel-licensecss/</link>
		<comments>http://www.zhangjingwei.com/archives/rel-licensecss/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 09:13:47 +0000</pubDate>
		<dc:creator>张经纬</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[rel]]></category>
		<category><![CDATA[sns]]></category>

		<guid isPermaLink="false">http://www.zhangjingwei.com/?p=1372</guid>
		<description><![CDATA[Rel-License 是微格式的开发标准之一，简单的说就是通过给引用标签（通常是链接）加上REL属性，来标明所引用链接/数据与文章的关系。 WordPress很早就引入了rel标准，在我们添加新链接的时候就可以看到“关系”属性。 早期某些社交类搜索引擎可根据这个标签来判断人与人之间的关系，但它对网页开发来说并无意义，值得庆幸的是随着浏览器的逐渐升级，我们可以利用CSS属性选择器以及REL来做一些有意思的功能。 这是一段带有REL属性的HTML结构。 &#60;ul&#62; &#60;li&#62;&#60;a href=&#34;#&#34; rel=&#34;civil&#34;&#62;小李&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#34;#&#34; rel=&#34;party&#34;&#62;局长&#60;/a&#62;&#60;/li&#62; &#60;/ul&#62; 页面中他呈现这个样子 因为局长和小李是两个不同的阶级，所以我们应该有区分他们，我打算在小李和局长后面增加两张图片让他表现出这个样式。 过去，我们需要在两个链接标签上增加不同的class来实现这种样式，并且我们需要针对不同的样式书写不同的CSS .c,.b &#123;background:url&#40;01.png&#41; right center no-repeat;&#125; .b &#123;background-image:url&#40;02.png&#41;;&#125; &#60;ul&#62; &#60;li&#62;&#60;a href=&#34;#&#34; rel=&#34;civil&#34; class=&#34;c&#34;&#62;小李&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#34;#&#34; rel=&#34;party&#34; class=&#34;b&#34;&#62;局长&#60;/a&#62;&#60;/li&#62; &#60;/ul&#62; 现在，我们可以利用REL属性以及属性选择器来完成这个工作。 a&#91;rel~=&#34;civil&#34;&#93;&#123;background:url&#40;01.png&#41; right center no-repeat;&#125; a&#91;rel~=&#34;party&#34;&#93;&#123;background:url&#40;02.png&#41; right center no-repeat;&#125; 同时，我们的HTML结构也可以剔除那些多余的样式了。 &#60;ul&#62; &#60;li&#62;&#60;a href=&#34;#&#34; rel=&#34;civil&#34;&#62;小李&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#34;#&#34; rel=&#34;party&#34;&#62;局长&#60;/a&#62;&#60;/li&#62; &#60;/ul&#62; 另外:ie6不支持属性选择器，但我们可以用JS来修复这个问题。 加入书签:]]></description>
			<content:encoded><![CDATA[<p><a href="http://microformats.org/wiki/rel-license">Rel-License</a> 是微格式的开发标准之一，简单的说就是通过给引用标签（通常是链接）加上REL属性，来标明所引用链接/数据与文章的关系。</p>
<p>WordPress很早就引入了rel标准，在我们添加新链接的时候就可以看到“关系”属性。</p>
<p>早期某些社交类搜索引擎可根据这个标签来判断人与人之间的关系，但它对网页开发来说并无意义，值得庆幸的是随着浏览器的逐渐升级，我们可以利用CSS属性选择器以及REL来做一些有意思的功能。</p>
<p>这是一段带有REL属性的HTML结构。</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;civil&quot;</span>&gt;</span>小李<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;party&quot;</span>&gt;</span>局长<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>页面中他呈现这个样子<br />
<a href="http://www.zhangjingwei.com/wp-content/uploads/2010/02/e1.png"><img src="http://www.zhangjingwei.com/wp-content/uploads/2010/02/e1.png" alt="example_01" title="example_01" width="238" height="148" class="alignnone size-full wp-image-1377" /></a></p>
<p>因为局长和小李是两个不同的阶级，所以我们应该有区分他们，我打算在小李和局长后面增加两张图片让他表现出这个样式。<br />
<a href="http://www.zhangjingwei.com/wp-content/uploads/2010/02/e2.png"><img src="http://www.zhangjingwei.com/wp-content/uploads/2010/02/e2.png" alt="e2" title="e2" width="169" height="115" class="alignnone size-full wp-image-1379" /></a></p>
<p>过去，我们需要在两个链接标签上增加不同的class来实现这种样式，并且我们需要针对不同的样式书写不同的CSS</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"> <span style="color: #6666ff;">.c</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.b</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>01.png<span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
 <span style="color: #6666ff;">.b</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>02.png<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;civil&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c&quot;</span>&gt;</span>小李<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;party&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;b&quot;</span>&gt;</span>局长<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>现在，我们可以利用REL属性以及属性选择器来完成这个工作。</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #00AA00;">&#91;</span>rel~<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;civil&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>01.png<span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a<span style="color: #00AA00;">&#91;</span>rel~<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;party&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>02.png<span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>同时，我们的HTML结构也可以剔除那些多余的样式了。</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;civil&quot;</span>&gt;</span>小李<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;party&quot;</span>&gt;</span>局长<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>另外:ie6不支持属性选择器，但我们可以用JS来修复这个问题。</p>



加入书签:


	<a rel="nofollow" class="thickbox" href="http://shuqian.qq.com/post?jumpback=1&title=Rel%E4%B8%8ECSS%E7%9A%84%E8%81%94%E5%90%88%E4%BD%BF%E7%94%A8&uri=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Frel-licensecss%2F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Frel-licensecss%2F&title=Rel%E4%B8%8ECSS%E7%9A%84%E8%81%94%E5%90%88%E4%BD%BF%E7%94%A8?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Frel-licensecss%2F&title=Rel%E4%B8%8ECSS%E7%9A%84%E8%81%94%E5%90%88%E4%BD%BF%E7%94%A8&n=1?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.haohaoreport.com/submit.php?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Frel-licensecss%2F&amp;title=Rel%E4%B8%8ECSS%E7%9A%84%E8%81%94%E5%90%88%E4%BD%BF%E7%94%A8?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/haohao.png" title="Haohao" alt="Haohao" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.zhangjingwei.com/feed/?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Rel%E4%B8%8ECSS%E7%9A%84%E8%81%94%E5%90%88%E4%BD%BF%E7%94%A8&amp;body=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Frel-licensecss%2F" title="email"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.zhangjingwei.com/archives/rel-licensecss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox的新属性 pointer-events</title>
		<link>http://www.zhangjingwei.com/archives/pointer-events/</link>
		<comments>http://www.zhangjingwei.com/archives/pointer-events/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 17:16:02 +0000</pubDate>
		<dc:creator>张经纬</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[pointer-events]]></category>

		<guid isPermaLink="false">http://www.zhangjingwei.com/?p=1297</guid>
		<description><![CDATA[Firefox 3.6 增加了对pointer-events的支持。Opera和safari都可以对svg的pointer-events属性做出支持，这次Firefox把他扩展到了常见的HTML元素上。 pointer-events的语法为 pointer-events: auto &#124; none &#124; visiblePainted &#124; visibleFill &#124; visibleStroke &#124; visible &#124; painted &#124; fill &#124; stroke &#124; all &#124; inherit 其中auto和none可针对所有的元素使用，其它的值只针对SVG。 （as of Firefox 3.6, only the values auto and none apply to all elements. The other values only apply to SVG and behave like auto in other XML [...]]]></description>
			<content:encoded><![CDATA[<p>Firefox 3.6 增加了对<a href="https://developer.mozilla.org/en/CSS/pointer-events" target="_blank">pointer-events</a>的支持。Opera和safari都可以对svg的pointer-events属性做出支持，这次Firefox把他扩展到了常见的HTML元素上。</p>
<p>pointer-events的语法为<br />
pointer-events:  auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | inherit</p>
<p>其中auto和none可针对所有的元素使用，其它的值只针对SVG。<br />
（as of Firefox 3.6, only the values auto and none apply to all elements. The other values only apply to SVG and behave like auto in other XML and HTML content.）</p>
<p>当使用none的时候，当前节点下的所有子节点不接受event事件。反之则接受。</p>
<p>例如当pointer-events为none时：</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#test</span> <span style="color: #00AA00;">&#123;</span>
    pointer-events<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#test</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>鼠标移动到p节点上时将没有不会触发任何事件。</p>
<p>值为auto时：<a href="http://www.zhangjingwei.com/demo/pointer-events/auto.htm" target="_blank">pointer-events/auto.htm</a></p>
<p>值为none时：<a href="http://www.zhangjingwei.com/demo/pointer-events/none.htm" target="_blank">pointer-events/none.htm</a></p>
<p>不过针对HTML元素是Firefox自己创造的新玩意。 ：）</p>
<p>参考：<br />
<a href="http://www.w3.org/TR/SVG/interact.html#PointerEventsProperty" target="_blank">http://www.w3.org/TR/SVG/interact.html#PointerEventsProperty</a><br />
<a href="http://hacks.mozilla.org/2009/12/pointer-events-for-html-in-firefox-3-6/" target="_blank">http://hacks.mozilla.org/2009/12/pointer-events-for-html-in-firefox-3-6/</a><br />
<a href="https://developer.mozilla.org/en/CSS/pointer-events" target="_blank">https://developer.mozilla.org/en/CSS/pointer-events</a></p>



加入书签:


	<a rel="nofollow" class="thickbox" href="http://shuqian.qq.com/post?jumpback=1&title=Firefox%E7%9A%84%E6%96%B0%E5%B1%9E%E6%80%A7%20pointer-events&uri=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fpointer-events%2F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fpointer-events%2F&title=Firefox%E7%9A%84%E6%96%B0%E5%B1%9E%E6%80%A7%20pointer-events?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fpointer-events%2F&title=Firefox%E7%9A%84%E6%96%B0%E5%B1%9E%E6%80%A7%20pointer-events&n=1?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.haohaoreport.com/submit.php?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fpointer-events%2F&amp;title=Firefox%E7%9A%84%E6%96%B0%E5%B1%9E%E6%80%A7%20pointer-events?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/haohao.png" title="Haohao" alt="Haohao" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.zhangjingwei.com/feed/?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Firefox%E7%9A%84%E6%96%B0%E5%B1%9E%E6%80%A7%20pointer-events&amp;body=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fpointer-events%2F" title="email"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.zhangjingwei.com/archives/pointer-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overflow Auto &amp;&amp; Position Relative</title>
		<link>http://www.zhangjingwei.com/archives/overflow-auto-and-position-relative/</link>
		<comments>http://www.zhangjingwei.com/archives/overflow-auto-and-position-relative/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 03:30:29 +0000</pubDate>
		<dc:creator>张经纬</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Overflow]]></category>
		<category><![CDATA[Position]]></category>

		<guid isPermaLink="false">http://www.zhangjingwei.com/?p=1142</guid>
		<description><![CDATA[常见的双倍边距类问题都遇到过，但很少遇到这种有意思的，所以记录一下。 这个BUG是发生在Standards模式下（就是包含XHTML或者HTML4.0的DOCTYPE时） 看这段代码 &#60; !DOCTYPE&#62; ul &#123;margin:0; padding:0;&#125; li &#123;list-style:none;&#125; #test&#123;overflow:auto;height:200px; widows:200px; border:1px solid #000;&#125; #test li &#123;position:relative;&#125; &#60;div id=&#34;test&#34;&#62; &#60;ul&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;li&#62;测试&#60;/li&#62; &#60;/ul&#62; &#60;/div&#62; 原本我认为溢出的文字会触发滚动条，但并没有呈现。 http://www.zhangjingwei.com/demo/overflow&#038;position/demo_01.html 在IE6或者IE7内，溢出的文字呈现绝对定位（position:absolute）的形式。 解决方法： 在父级元素元素上设置属性position:relative http://www.zhangjingwei.com/demo/overflow&#038;position/demo_02.html 来源：http://rowanw.com/bugs/overflow_relative.htm 加入书签:]]></description>
			<content:encoded><![CDATA[<p>常见的双倍边距类问题都遇到过，但很少遇到这种有意思的，所以记录一下。</p>
<p>这个BUG是发生在Standards模式下（就是包含XHTML或者HTML4.0的DOCTYPE时）</p>
<p>看这段代码</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #009900;">&lt; !DOCTYPE&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">ul <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
li <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#test</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>height<span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">widows</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#test</span> li <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;test&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>测试<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>原本我认为溢出的文字会触发滚动条，但并没有呈现。<br />
<a href="http://www.zhangjingwei.com/demo/overflow&#038;position/demo_01.html">http://www.zhangjingwei.com/demo/overflow&#038;position/demo_01.html</a><br />
在IE6或者IE7内，溢出的文字呈现绝对定位（position:absolute）的形式。</p>
<p>解决方法：<br />
在父级元素元素上设置属性position:relative<br />
<a href="http://www.zhangjingwei.com/demo/overflow&#038;position/demo_02.html">http://www.zhangjingwei.com/demo/overflow&#038;position/demo_02.html</a></p>
<p>来源：<a href="http://rowanw.com/bugs/overflow_relative.htm">http://rowanw.com/bugs/overflow_relative.htm</a></p>



加入书签:


	<a rel="nofollow" class="thickbox" href="http://shuqian.qq.com/post?jumpback=1&title=Overflow%20Auto%20%26%26%20Position%20Relative&uri=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Foverflow-auto-and-position-relative%2F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Foverflow-auto-and-position-relative%2F&title=Overflow%20Auto%20%26%26%20Position%20Relative?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Foverflow-auto-and-position-relative%2F&title=Overflow%20Auto%20%26%26%20Position%20Relative&n=1?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.haohaoreport.com/submit.php?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Foverflow-auto-and-position-relative%2F&amp;title=Overflow%20Auto%20%26%26%20Position%20Relative?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/haohao.png" title="Haohao" alt="Haohao" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.zhangjingwei.com/feed/?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Overflow%20Auto%20%26%26%20Position%20Relative&amp;body=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Foverflow-auto-and-position-relative%2F" title="email"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.zhangjingwei.com/archives/overflow-auto-and-position-relative/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CSS 的模块化思想</title>
		<link>http://www.zhangjingwei.com/archives/css-block/</link>
		<comments>http://www.zhangjingwei.com/archives/css-block/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 15:41:48 +0000</pubDate>
		<dc:creator>张经纬</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[模块化]]></category>

		<guid isPermaLink="false">http://www.zhangjingwei.com/?p=553</guid>
		<description><![CDATA[在Twinsen Liang的博客上看到一篇名为语义化单单的限定在html么？的文章，文中主要是提及了CSS的命名规则，仔细阅读后，我认为这个其实就是模块化思想。（作者也提了这一点）。 我没有看过CSS模块化的相关书籍，所以我下面说的不一定正确，但是在工作中，我会用我理解的模块化方式提高工作效率，我理解的模块化，主要分为两类。 1、将常见的样式剥离出来，形成单独的样式，我叫他基础样式表或模块样式表，这个样式表主要一些常见的基本结构和形式，如CSS Reset、Blank、Font 等等。 例如下面这个样式表，我认为就是一个简单的基础样式表。（只是简单，不推荐用） * &#123;margin:0;padding:0;border:none;outline:none;&#125; .cb &#123;clear:both;&#125; .blank10 &#123;height:10px; font-size:1px; overflow:hidden; clear:both;&#125; 2、在页面中按照结构模块化书写样式表，避免样式之间的干扰，并且方便浏览。 例如下面的这个结构 &#60;!-- 左边 --&#62; &#60;div&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;/div&#62; &#60;!-- 右边 --&#62; &#60;div&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;/div&#62; 有一部分同学可能会这样写 .wrap_content_box &#123;float:left;&#125; .wrap_content_box h2 &#123;...&#125; &#60;!-- 左边 --&#62; &#60;div class=&#34;wrap_content_box&#34;&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;/div&#62; &#60;!-- 右边 --&#62; &#60;div class=&#34;wrap_content_box&#34;&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;h2&#62;...&#60;/h2&#62; &#60;/div&#62; 刚刚看上去的时候效果很不错，一切都很完美，代码少，效果也实现了，但如果有一天，我们需要将所有h2的样式变的各不相同时，情况仿佛不乐观了。 [...]]]></description>
			<content:encoded><![CDATA[<p>在Twinsen Liang的博客上看到一篇名为<a href="http://www.twinsenliang.net/skill/20081129.html">语义化单单的限定在html么？</a>的文章，文中主要是提及了CSS的命名规则，仔细阅读后，我认为这个其实就是模块化思想。（作者也提了这一点）。</p>
<p>我没有看过CSS模块化的相关书籍，所以我下面说的不一定正确，但是在工作中，我会用我理解的模块化方式提高工作效率，我理解的模块化，主要分为两类。</p>
<p>1、将常见的样式剥离出来，形成单独的样式，我叫他基础样式表或模块样式表，这个样式表主要一些常见的基本结构和形式，如CSS Reset、Blank、Font 等等。</p>
<p>例如下面这个样式表，我认为就是一个简单的基础样式表。（只是简单，不推荐用）</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>border<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>outline<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.cb</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.blank10</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>2、在页面中按照结构模块化书写样式表，避免样式之间的干扰，并且方便浏览。<br />
例如下面的这个结构</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- 左边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 右边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>有一部分同学可能会这样写</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.wrap_content_box</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.wrap_content_box</span> h2 <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- 左边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 右边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>刚刚看上去的时候效果很不错，一切都很完美，代码少，效果也实现了，但如果有一天，我们需要将所有h2的样式变的各不相同时，情况仿佛不乐观了。</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.wrap_content_box</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
h2<span style="color: #6666ff;">.XX</span> <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span>
h2<span style="color: #6666ff;">.YY</span> <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span>
h2<span style="color: #6666ff;">.ZZ</span> <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span>
h2<span style="color: #6666ff;">.XYZ</span> <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- 左边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;XX&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;YY&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 右边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ZZ&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> calss<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;XYZ&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>迫不得已的，我们增加了很多带有不同标记的样式。可是1年后呢有人问起你这些样式所控制的对象是什么？<br />
我可以肯定你会说，“我很费解”。<br />
或者当你自己又写了一个“h2.XX”（命名重复的情况经常出现），无意覆盖了这个1年前的样式，而你又不知道，又恰巧被你的老板发现了&#8230;&#8230;.上帝只能说，阿门，哥们，点被不能怨上帝。</p>
<p>可如果在一开始我们用这种方法写呢？</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.wrap_content_box</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_con_00</span> h2<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#wrap_con_01</span> h2 <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- 左边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_con_00&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 右边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_con_01&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>粗看是多了一些，但是当我们再次遇见给h2增加不同样式的时候，我们可以&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.wrap_content_box</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_con_00</span> h2<span style="color: #00AA00;">,</span><span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_con_00</span> h2<span style="color: #6666ff;">.first</span> <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_con_01</span> h2<span style="color: #00AA00;">,</span><span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_con_01</span> h2<span style="color: #6666ff;">.first</span> <span style="color: #00AA00;">&#123;</span>...<span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- 左边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_con_00&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;first&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 右边 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_con_01&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_content_box&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;first&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>看，这样是不是好多了，这种格式在1年后，有人问起的时候，我肯以肯定你会说“我不费解”。<br />
上帝也不会找你麻烦了。 <img src='http://www.zhangjingwei.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>



加入书签:


	<a rel="nofollow" class="thickbox" href="http://shuqian.qq.com/post?jumpback=1&title=CSS%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E6%80%9D%E6%83%B3&uri=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss-block%2F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss-block%2F&title=CSS%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E6%80%9D%E6%83%B3?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss-block%2F&title=CSS%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E6%80%9D%E6%83%B3&n=1?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.haohaoreport.com/submit.php?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss-block%2F&amp;title=CSS%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E6%80%9D%E6%83%B3?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/haohao.png" title="Haohao" alt="Haohao" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.zhangjingwei.com/feed/?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E6%80%9D%E6%83%B3&amp;body=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Fcss-block%2F" title="email"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.zhangjingwei.com/archives/css-block/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>取消透明度继承的方法</title>
		<link>http://www.zhangjingwei.com/archives/fix_opacity/</link>
		<comments>http://www.zhangjingwei.com/archives/fix_opacity/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 16:00:28 +0000</pubDate>
		<dc:creator>张经纬</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[继承]]></category>
		<category><![CDATA[透明度]]></category>

		<guid isPermaLink="false">http://www.zhangjingwei.com/?p=521</guid>
		<description><![CDATA[文中的内容使用叠盖的方法组合而成，已经没有继承了，文章标题，有歧义，回复中有朋友提出来了这一点，这里补充说明。 最近做活动页面的时候，遇到一个透明层的问题。当父级元素设置透明度后，子元素继承(inherit)了父元素的透明度值。在网上找了一下，虽然Google到一个取消透明度继承的,但是那个方法用到太多的CSS HACK，指不定什么时候浏览器升级了，这些HACK就成了地雷。于是自己琢磨了一个办法，取消了透明度的继承，并且没有使用到HACK。 思路： 利用相对定位和绝对定位。相对定位撑开高度，绝对定位充当透明层。相对定位的元素盖在绝对定位的层上。 问题： 绝对定位中没有内容，要事先声明有一个绝对高的高度，但是不能超过32768像素。 Demo： http://www.zhangjingwei.com/demo/fix_opacity/ 样式表如下 body &#123; background:url&#40;http://www.google.com/intl/en_ALL/images/logo.gif&#41; repeat; &#125; #wrap_1 &#123; width:300px; padding:20px; color:#F00; background:#000; position:relative; filter:alpha&#40;opacity=50&#41;; -ms-filter:&#34;alpha(opacity=50)&#34;; -moz-opacity:0.5; -khtml-opacity: 0.5; opacity:0.5; &#125; #wrap_2 &#123; width:300px; padding:20px; color:#F00; position:relative; /*父元素为相对定位*/ overflow:hidden; &#125; #wrap_2_content &#123; position:relative; /*内容相对定位，盖在透明层上*/ &#125; #wrap_2 .fixopacity &#123; width:340px; background:#000; height:32768px; /*一个足够高的高度*/ position:absolute; /*使用绝对定位*/ top:0; left:0; z-index:-1; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>文中的内容使用叠盖的方法组合而成，已经没有继承了，文章标题，有歧义，回复中有朋友提出来了这一点，这里补充说明。</strong></p>
<p>最近做活动页面的时候，遇到一个透明层的问题。当父级元素设置透明度后，子元素继承(inherit)了父元素的透明度值。在网上找了一下，虽然<a href="http://www.google.cn/search?hl=zh-CN&amp;newwindow=1&amp;q=css+%E9%80%8F%E6%98%8E%E5%BA%A6+%E7%BB%A7%E6%89%BF&amp;btnG=Google+%E6%90%9C%E7%B4%A2&amp;meta=&amp;aq=f&amp;oq=" target="_blank">Google到一个取消透明度继承</a>的,但是那个方法用到太多的CSS HACK，指不定什么时候浏览器升级了，这些HACK就成了地雷。于是自己琢磨了一个办法，取消了透明度的继承，并且没有使用到HACK。</p>
<p>思路：<br />
利用相对定位和绝对定位。相对定位撑开高度，绝对定位充当透明层。相对定位的元素盖在绝对定位的层上。</p>
<p>问题：<br />
绝对定位中没有内容，要事先声明有一个绝对高的高度，但是不能超过32768像素。</p>
<p>Demo：<br />
<a href="http://www.zhangjingwei.com/demo/fix_opacity/" target="_blank">http://www.zhangjingwei.com/demo/fix_opacity/</a></p>
<p>样式表如下</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">http://www.google.com/intl/en_ALL/images/logo.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_1</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F00</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	filter<span style="color: #00AA00;">:</span>alpha<span style="color: #00AA00;">&#40;</span>opacity<span style="color: #00AA00;">=</span><span style="color: #cc66cc;">50</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-ms-filter<span style="color: #00AA00;">:</span><span style="color: #ff0000;">&quot;alpha(opacity=50)&quot;</span><span style="color: #00AA00;">;</span>
	-moz-opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
	-khtml-opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
	opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_2</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F00</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*父元素为相对定位*/</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_2_content</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*内容相对定位，盖在透明层上*/</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap_2</span> <span style="color: #6666ff;">.fixopacity</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">340px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">32768px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*一个足够高的高度*/</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*使用绝对定位*/</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span>-<span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*置于最低层*/</span>
	filter<span style="color: #00AA00;">:</span>alpha<span style="color: #00AA00;">&#40;</span>opacity<span style="color: #00AA00;">=</span><span style="color: #cc66cc;">50</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-ms-filter<span style="color: #00AA00;">:</span><span style="color: #ff0000;">&quot;alpha(opacity=50)&quot;</span><span style="color: #00AA00;">;</span>
	-moz-opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
	-khtml-opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
	opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.bk10</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>HTML代码如下</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_1&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>没有取消透明度的继承的样子<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>当我们设置了父级元素透明度的时候，子元素往往都会继承这个透明度。本例旨在演示取消这个透明度。<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://at.the9.com/images/library/common/library_logo.png&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;105&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;113&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bk10&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 主代码 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_2&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrap_2_content&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>取消透明度的继承的样子<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>当我们设置了父级元素透明度的时候，子元素往往都会继承这个透明度。本例旨在演示取消这个透明度。<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://at.the9.com/images/library/common/library_logo.png&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;105&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;113&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fixopacity&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- 主代码 --&gt;</span></pre></div></div>




加入书签:


	<a rel="nofollow" class="thickbox" href="http://shuqian.qq.com/post?jumpback=1&title=%E5%8F%96%E6%B6%88%E9%80%8F%E6%98%8E%E5%BA%A6%E7%BB%A7%E6%89%BF%E7%9A%84%E6%96%B9%E6%B3%95&uri=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Ffix_opacity%2F?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Ffix_opacity%2F&title=%E5%8F%96%E6%B6%88%E9%80%8F%E6%98%8E%E5%BA%A6%E7%BB%A7%E6%89%BF%E7%9A%84%E6%96%B9%E6%B3%95?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Ffix_opacity%2F&title=%E5%8F%96%E6%B6%88%E9%80%8F%E6%98%8E%E5%BA%A6%E7%BB%A7%E6%89%BF%E7%9A%84%E6%96%B9%E6%B3%95&n=1?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.haohaoreport.com/submit.php?url=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Ffix_opacity%2F&amp;title=%E5%8F%96%E6%B6%88%E9%80%8F%E6%98%8E%E5%BA%A6%E7%BB%A7%E6%89%BF%E7%9A%84%E6%96%B9%E6%B3%95?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/haohao.png" title="Haohao" alt="Haohao" class="sociable-hovers" /></a>
	<a rel="nofollow" class="thickbox" href="http://www.zhangjingwei.com/feed/?TB_iframe=true&amp;height=500&amp;width=900"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=%E5%8F%96%E6%B6%88%E9%80%8F%E6%98%8E%E5%BA%A6%E7%BB%A7%E6%89%BF%E7%9A%84%E6%96%B9%E6%B3%95&amp;body=http%3A%2F%2Fwww.zhangjingwei.com%2Farchives%2Ffix_opacity%2F" title="email"><img src="http://www.zhangjingwei.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.zhangjingwei.com/archives/fix_opacity/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
