<?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>随网之舞hack</title>
	<atom:link href="http://dancewithnet.com/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://dancewithnet.com</link>
	<description>WEB Design{HTML:CSS:Javascript:DOM:AJAX:PHP:Usability}/Viewpoint/Photo/Food/Mood</description>
	<lastBuildDate>Mon, 18 Jul 2011 02:45:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Hacks</title>
		<link>http://dancewithnet.com/2008/07/12/css-hacks/</link>
		<comments>http://dancewithnet.com/2008/07/12/css-hacks/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 19:05:48 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[hack]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1347</guid>
		<description><![CDATA[Java一直标榜一句老话叫“编写一次，到处运行(Write Once,Run Anywhere)”，CSS也差一点点做到了。但就是为了差的一点点往往需要大量的工作，虽然这并不是CSS的错。基本上别妄想兼容所有的解析器... ]]></description>
			<content:encoded><![CDATA[<p>Java一直标榜一句老话叫“编写一次，到处运行(Write Once,Run Anywhere)”，CSS也差一点点做到了。但就是为了差的一点点往往需要大量的工作，虽然这并不是CSS的错。基本上别妄想兼容所有的解析器了，仅仅是为了让网页在<a href="http://developer.yahoo.com/yui/">YUI</a>中列举的<a href="http://developer.yahoo.com/yui/articles/gbs/index.html#gbschart">A级浏览器</a>呈现一致就不是一件特别容易的事情。虽然通过精心的组织HTML结构加上使用最合适最通用的CSS代码可能实现多浏览器呈现一致，但当在视觉的过度设计、精确到像素的规定和前端快速实现的要求的前提下，可能你不得不为不同的浏览器写不同的CSS代码，这就是CSS Hacks了。我们的目标是保持CSS简洁和没有CSS Hacks，但即使多年以前就呼吁<a href="http://www.digital-web.com/articles/keep_css_simple/">Keep CSS simple</a>的PPK也不得不在<a href="http://www.quirksmode.org/">他的网站</a>中使用CSS Hacks，即便如此其站点在所有的A级浏览器中也无法保持一致的呈现。所以，下面这个我常用的CSS Hacks列表或许有些用：<span id="more-1347"></span></p>
<table class="stat">
<tr>
<th></th>
<th>IE6</th>
<th>IE7</th>
<th>Firefox2+</th>
<th>Firefox3+</th>
<th>Opera9.5+</th>
<th>Safari3.1+</th>
</tr>
<tr>
<th>选择符{<br />
&nbsp;&nbsp;*属性:值;<br />
}<sup>[1]</sup></th>
<td>√</td>
<td>√</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>选择符{<br />
&nbsp;&nbsp;_属性:值;<br />
}</th>
<td>√</td>
<td>×<sup>[2]</sup></td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>选择符,x:-moz-any-link{<br />
&nbsp;&nbsp;属性:值;<br />
}</th>
<td>×</td>
<td>√</td>
<td>√</td>
<td>√</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>选择符,x:-moz-any-link,x:default{<br />
&nbsp;&nbsp;属性:值;<br />
}</th>
<td>×</td>
<td>√</td>
<td>×</td>
<td>√</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>@media all and (min-width:0){<br />
&nbsp;&nbsp;选择符{属性:值;}<br />
}<sup>[3]</sup>
</th>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>√</td>
<td>√</td>
</tr>
<tr>
<th>@media all and (-webkit-min-device-pixel-ratio:0){<br />
&nbsp;&nbsp;选择符{属性:值;}<br />
}<sup>[4]</sup>
</th>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>√</td>
</tr>
</table>
<p>这里有一个<a href="http://dancewithnet.com/lab/2008/css-hacks/" class="link-btn">上述CSS Hacks的应用的例子</a>可以看看。</p>
<ul class="refer">
<li>[1]&nbsp;此处的*号其实也可以是.号、&gt;号、+号和#号。但它们都不属于CSS2.1规范合法属性名的一部分，所以不能通过验证。</li>
<li>[2]&nbsp;当IE7为<a href="http://hsivonen.iki.fi/doctype/">quriks mode</a>时和IE6为quriks mode解析相同，所以此时这个表达式在IE7中也能生效。<a href="http://wellstyled.com/css-underscore-hack.html">这个hack已经应用了很久了</a>，下划线_作为属性名的前缀是符合CSS2.1规范语法的，但不存在于其属性名列表中，所以依旧不能通过标准语法验证。对于多个IE的CSS Hacks，<a href="http://dancewithnet.com/2006/06/06/ie-conditional-comments/">条件注释</a>是一个很值得考虑的解决方案。另外对于IE8可以关注其新功能和变化，但现在考虑其CSS Hacks问题有点过早，真的有需求可以通过增加<a href="http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx">&lt;meta http-equiv=&#8221;X-UA-Compatible&#8221; content=&#8221;IE=EmulateIE7&#8243; /&gt;</a>来解决。</li>
<li>[3]&nbsp;如果把表达式中的and和(中间的空白去掉变成@media all and(min-width:0){选择符{属性:值;}}，那么Safari3+将无法识别，Opera9.5+则可以。</li>
<li>[4]&nbsp;这个表达式Opera9.0是支持的。</li>
</ul>
<p>上面这些CSS Hacks仅仅是沧海一粟，是一些简单的通用的CSS Hacks。这个世界上还存在很多很知名很经典的CSS Hacks，更多的CSS Hacks可以看这里：</p>
<ol>
<li><a href="http://paulirish.com/2009/browser-specific-css-hacks/">Browser CSS hacks</a></li>
<li><a href="http://www.nealgrosskopf.com/tech/thread.php?pid=20">CSS Browser Hacks For Firefox, Opera, Safari &#038; Internet Explorer</a></li>
<li><a href="http://perishablepress.com/press/2009/06/28/css-hacks-for-different-versions-of-firefox/">CSS Hacks for Different Versions of Firefox</a></li>
<li><a href="http://www.webdevout.net/css-hacks">CSS hacks</a></li>
<li><a href="http://css-discuss.incutio.com/?page=CssHack">CSS Hack</a></li>
<li><a href="http://centricle.com/ref/css/filters/">Will the browser apply the rule(s)?</a></li>
<li><a href="http://www.ericmeyeroncss.com/bonus/trick-hide.html">Tricking Browsers and Hiding Styles</a></li>
<li><a href="http://realazy.org/blog/2006/07/31/working-with-buggy-browsers-2/">与臭虫为友——浏览器补救办法，臭虫以及解决方案（第二部分）</a></li>
<li><a href="http://perishablepress.com/press/2008/07/15/css-hackz-series-targeting-and-filtering-internet-explorer-7/">CSS Hackz Series: Targeting and Filtering Internet Explorer 7</a></li>
<li><a href="http://www.virtuosimedia.com/tutorials/ultimate-ie6-cheatsheet-how-to-fix-25-internet-explorer-6-bugs">Ultimate IE6 Cheatsheet: How To Fix 25+ Internet Explorer 6 Bugs</a>&#8212;<a href="http://www.vfresh.org/w3c/727">中文版</a></li>
<li><a href="http://blog.gulu77.com/?p=59">CSS让你的IE浏览器崩溃</a></li>
<li><a href="http://haslayout.net/css/index">Internet Explorer CSS Bugs</a>&#8212;<a href="http://coolshell.cn/?p=1245">中文版</a></li>
<li><a href="http://www.css88.com/archives/579">【IE6的疯狂系列】IE6 BUG大全</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/07/12/css-hacks/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

