<?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; ie6</title>
	<atom:link href="http://blog.wabow.com/archives/tag/ie6/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.wabow.com</link>
	<description>Wabow Information Inc. Blog</description>
	<lastBuildDate>Fri, 20 Jan 2012 09:19:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[CSS] IE6 模擬 position:fixed 純 CSS 解法</title>
		<link>http://blog.wabow.com/archives/1384</link>
		<comments>http://blog.wabow.com/archives/1384#comments</comments>
		<pubDate>Sat, 06 Jun 2009 04:19:31 +0000</pubDate>
		<dc:creator>jaceju</dc:creator>
				<category><![CDATA[技術分享]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ie6]]></category>

		<guid isPermaLink="false">http://blog.wabow.com/?p=1384</guid>
		<description><![CDATA[本文轉載自[CSS] IE6 模擬 position:fixed 純 CSS 解法 我們都知道 IE6 不支援 position:fixed 。 但 position:fixed 真的很好用，像是廣告、選單這些頁面上常見常用的元素，需要固定在頁面上某個位置時，都可以用 position:fixed 來處理。 所以有很多網路上的先進想出了很多方法來解決 IE6 不支援 position:fixed 的問題，而大部份的解法都是採用 JavaScript 。可惜這些解法除了要擔心瀏覽器關閉 JavaScript 外，通常在移動時都會有抖動的跡象。 所以我就想找找看網路上有沒有純 CSS 解法，沒想到就找到了這篇： Fixing position:fixed for Windows Internet Explorer 。 直接來看範例： fixed.html &#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62; &#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62; &#60;head&#62; &#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34; /&#62; &#60;title&#62;Position:fixed [...]]]></description>
			<content:encoded><![CDATA[<p>本文轉載自<a href="http://www.jaceju.net/blog/?p=577">[CSS] IE6 模擬 position:fixed 純 CSS 解法</a></p>
<p>我們都知道 IE6 不支援 position:fixed 。</p>
<p>但 position:fixed 真的很好用，像是廣告、選單這些頁面上常見常用的元素，需要固定在頁面上某個位置時，都可以用 position:fixed 來處理。</p>
<p>所以有很多網路上的先進想出了很多方法來解決 IE6 不支援 position:fixed 的問題，而大部份的解法都是採用 JavaScript 。可惜這些解法除了要擔心瀏覽器關閉 JavaScript 外，通常在移動時都會有抖動的跡象。</p>
<p class="image"><img src="http://www.jaceju.net/resources/pure_css_position_fixed/position_fixed_not_really.png" alt="fixed...not really" /></p>
<p><span id="more-1384"></span></p>
<p>所以我就想找找看網路上有沒有純 CSS 解法，沒想到就找到了這篇： <a href="http://tagsoup.com/cookbook/css/fixed/">Fixing position:fixed for Windows Internet Explorer</a> 。</p>
<p>直接來看<a href="http://www.jaceju.net/resources/pure_css_position_fixed/fixed.html">範例</a>：</p>
<p>fixed.html</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Position:fixed on pure css&lt;/title&gt;
&lt;link href=&quot;fixed.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;div id=&quot;wrapper&quot;&gt;
&lt;p&gt;TEST LINE &lt;/p&gt;
&lt;p&gt;TEST LINE&lt;/p&gt;
&lt;p&gt;TEST LINE&lt;/p&gt;
&lt;p&gt;TEST LINE&lt;/p&gt;
...
&lt;p&gt;TEST LINE&lt;/p&gt;
&lt;p&gt;TEST LINE&lt;/p&gt;
&lt;p&gt;TEST LINE&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&quot;fixed&quot;&gt;
&lt;ul&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;li&gt;ITEM 4&lt;/li&gt;
&lt;li&gt;ITEM 5&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>首先我們先把要捲動的部份用 div#wrapper 包起來，要固定的部份 (div#fixed) 則排除在 div#wrapper 之外；然後先對有支援 position:fixed 的瀏覽器做處理，也就是直接利用 position:fixed 來將 div#fixed 定位。</p>
<p class="image"><img src="http://www.jaceju.net/resources/pure_css_position_fixed/fixed_scrollable.png" alt="fixed and scrollable" /></p>
<p>再來是 CSS 的部份：</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">html<span style="color: #00AA00;">,</span> body<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>
&nbsp;
<span style="color: #cc00cc;">#fixed</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;">fixed</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">380px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>接下來我們再針對 IE6 做處理，也就是用 * html 這個 hack ：</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> html <span style="color: #00AA00;">&#123;</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>
&nbsp;
<span style="color: #00AA00;">*</span> html body<span style="color: #00AA00;">,</span>
<span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#wrapper</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;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</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>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#fixed</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;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>這裡的原理很簡單，就是將 div#wrapper 的高度設為與 body 同高， overflow 設為 auto 即可。</p>
<p class="note">註：上面那篇參考文章裡只提到 body 要設為高度 100% 和 overflow 為 auto ，但我實驗的結果是連 div#wrapper 也要設成一樣，才會正常動作。</p>
<p>最後把固定的部份用 position:absolute 定住，這樣就完成讓 IE6 模擬 position:fixed 的效果啦~</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.wabow.com/archives/1384/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

