<?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>IInterest &#187; 等高</title>
	<atom:link href="http://www.iinterest.net/tag/%e7%ad%89%e9%ab%98/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iinterest.net</link>
	<description>关注移动互联网 &#38; HTML5</description>
	<lastBuildDate>Sat, 07 Jan 2012 08:07:27 +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跨浏览器的多列等高(2)</title>
		<link>http://www.iinterest.net/2009/07/15/equal-height-columns2/</link>
		<comments>http://www.iinterest.net/2009/07/15/equal-height-columns2/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 04:05:47 +0000</pubDate>
		<dc:creator>Bell</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[等高]]></category>

		<guid isPermaLink="false">http://iinterest.net/blog/?p=328</guid>
		<description><![CDATA[昨天转了篇多列等高的文章:Equal Height Columns with Cross-Browser CSS and No Hacks(译:纯 CSS 无 Hack 跨浏览器的多列等高),虽然介绍的方法实现起来比较复杂,但Matthew James Taylor的创新思维还是值得学习,借助作者的思路,自己写了个比较简化的例子. 先来看看实例:(兼容IE6-8,FF,OPERA等主流的浏览器) &#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Strict//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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=gb2312&#34; /&#62; &#60;title&#62;iinterest&#60;/title&#62; &#60;style type=&#34;text/css&#34;&#62; *{ margin:0; padding:0;} .wrapper{ width:960px; &#8230; <a href="http://www.iinterest.net/2009/07/15/equal-height-columns2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>昨天转了篇多列等高的文章:<a href="http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks">Equal Height Columns with Cross-Browser CSS and No Hacks</a>(<a href="http://iinterest.net/blog/2009/07/14/equal-height-columns-with-cross-browser/" target="_blank">译:纯 CSS 无 Hack 跨浏览器的多列等高</a>),虽然介绍的方法实现起来比较复杂,但<a href="http://matthewjamestaylor.com/about">Matthew James Taylor</a>的创新思维还是值得学习,借助作者的思路,自己写了个比较简化的例子.</p>
<p>先来看看实例:(兼容IE6-8,FF,OPERA等主流的浏览器)<br />
<span id="more-328"></span></p>
<div class="runcode">
<p><textarea name="runcode" class="runcode_text" id="runcode_gjSlWj">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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=gb2312&quot; /&gt;
&lt;title&gt;iinterest&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
*{ margin:0; padding:0;}
.wrapper{ width:960px; margin:0 auto; background:#6CF; overflow:hidden;}
	.sidebar-bg{ float:left; width:100%; margin-left:600px; background:#FC3;}
		.main{ float:left; width:600px; margin-left:-600px;}
		.sidebar{ float:left; width:360px;}
/* IE6 hack*/
* html .sidebar-bg{ display:inline; }
* html .main{ position:relative; display:inline; z-index:1;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;wrapper&quot;&gt;
	&lt;div class=&quot;sidebar-bg&quot;&gt;
    	&lt;div class=&quot;main&quot;&gt;
        	&lt;p&gt;
            	main&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;
            &lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sidebar&quot;&gt;
        	&lt;p&gt;
            	sidebar&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;
            &lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea></p>
<p><input type="button" value="运行" class="runcode_button" onclick="runcode_open_new('runcode_gjSlWj');"/> <input type="button" value="复制" class="runcode_button" onclick="runcode_copy('runcode_gjSlWj');"/> 提示：你可以先修改部分代码再运行。</p>
</div>
<p>与作者的思路是一样的,只是改用margin来实现</p>
<p>再介绍一种更为简洁的方法:</p>
<p>实例:(兼容:同上&#8230;^_^)</p>
<div class="runcode">
<p><textarea name="runcode" class="runcode_text" id="runcode_VswX5v">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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=gb2312&quot; /&gt;
&lt;title&gt;iinterest&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
*{ margin:0; padding:0;}
.wrapper{ width:960px; margin:0 auto; overflow:hidden;}
	.main{ float:left; width:300px; background:#6CF; padding-bottom:32767px; margin-bottom:-32767px;}
	.sidebar{ float:left; width:360px; background:#FC3; padding-bottom:32767px; margin-bottom:-32767px;}
	.sidebar-sub{ float:left; width:300px; background:#6C3; padding-bottom:32767px; margin-bottom:-32767px;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;wrapper&quot;&gt;
	&lt;div class=&quot;main&quot;&gt;
    	&lt;p&gt;
            main&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;
        &lt;/p&gt;
    &lt;/div&gt;
    &lt;div class=&quot;sidebar&quot;&gt;
        sidebar&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;
    &lt;/div&gt;
    &lt;div class=&quot;sidebar-sub&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea></p>
<p><input type="button" value="运行" class="runcode_button" onclick="runcode_open_new('runcode_VswX5v');"/> <input type="button" value="复制" class="runcode_button" onclick="runcode_copy('runcode_VswX5v');"/> 提示：你可以先修改部分代码再运行。</p>
</div>
<p>一些必要的解释:</p>
<p>1.原理:利用padding-bottom将列的高拉长(padding内是可以实现background属性的)，而负的margin-bottom又使其回到底部开始的位置(使显示的内容回到开头的位置)，同时，溢出部分隐藏掉了。</p>
<p>2.padding-bottom:32767px; 其实padding-bottom的值可以随意点,只要大于你页面的高度就行,之所以用<span style="color: #ff0000;">32767</span>是因为int的最大正值就是32767,没有比这个更大的了,所以用着省心,呵呵</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iinterest.net/2009/07/15/equal-height-columns2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[翻译]纯 CSS 无 Hack 跨浏览器的多列等高</title>
		<link>http://www.iinterest.net/2009/07/14/equal-height-columns-with-cross-browser/</link>
		<comments>http://www.iinterest.net/2009/07/14/equal-height-columns-with-cross-browser/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 08:19:34 +0000</pubDate>
		<dc:creator>Bell</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[等高]]></category>

		<guid isPermaLink="false">http://iinterest.net/blog/?p=322</guid>
		<description><![CDATA[原文：Equal Height Columns with Cross-Browser CSS and No Hacks 作者：Matthew James Taylor 翻译：ytzong 纯 CSS 打造多列等高并不像想象中那么容易。本文着重讲述多列布局出现的问题，之后提供一个在所有浏览器都正常工作的简单解决方案。这个方法 100% 无 CSS hack，无图片，无 javascript，甚至可以用在最严格编码的网站上。 多列等高的问题   上例中有包含不同内容的 3 列，可以看出存在的问题是列的背景色随着其包含内容的高度而自适应展开。这是我们要解决的问题。如何使所有的列等高？或具体的说，如何使所有列的高度等于最高列的高度？这很棘手，因为我们不清楚每列将会多高，哪一列是最高的。不能简单的给所有列一个固定的高度，如果内容很少将会导致页面底部有大片空白；如果内容太多则会在文字显示完全前关闭。两种情形都不妥。实际上，内容的长度是动态的，所以每列的高度也是动态的。必须意识到 Web 上没有固定的东东，乡民们有不同的屏幕分辨率，浏览器中的文字也可能被设置为任意大小，所有这些都会影响内容的高度。 分离列内容与其背景色 解决等高问题的第一步是把能分离的破开。方法是每列用两个 div 替代原来的一个。第一个 div 用来放内容，另一个用来作背景色。分离使我们可以单独控制这些额外的元素，之后用更有效的方法把它们放在一起。答案呼之欲出。 浮动的容器的高度始终取决于其浮动的内容（高度） 这是本文多列等高方法的核心。 使一个 div 的高度等于最高列高度的唯一方法是这个 div &#8230; <a href="http://www.iinterest.net/2009/07/14/equal-height-columns-with-cross-browser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<ul>
<li>原文：<a href="http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks">Equal Height Columns with Cross-Browser CSS and No Hacks</a></li>
<li>作者：<a href="http://matthewjamestaylor.com/about">Matthew James Taylor</a></li>
<li>翻译：<a href="https://twitter.com/ytzong">ytzong</a></li>
</ul>
<p>纯 CSS 打造多列等高并不像想象中那么容易。本文着重讲述多列布局出现的问题，之后提供一个在所有浏览器都正常工作的简单解决方案。这个方法 100% 无 CSS hack，无图片，无 javascript，甚至可以用在最严格编码的网站上。</p>
<p><strong>多列等高的问题</strong></p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-problem.gif" alt="" /> <br />
<span id="more-322"></span></p>
<p>上例中有包含不同内容的 3 列，可以看出存在的问题是列的背景色随着其包含内容的高度而自适应展开。这是我们要解决的问题。如何使所有的列等高？或具体的说，如何使所有列的高度等于最高列的高度？这很棘手，因为我们不清楚每列将会多高，哪一列是最高的。不能简单的给所有列一个固定的高度，如果内容很少将会导致页面底部有大片空白；如果内容太多则会在文字显示完全前关闭。两种情形都不妥。实际上，内容的长度是动态的，所以每列的高度也是动态的。必须意识到 Web 上没有固定的东东，乡民们有不同的屏幕分辨率，浏览器中的文字也可能被设置为任意大小，所有这些都会影响内容的高度。</p>
<p><strong>分离列内容与其背景色</strong></p>
<p>解决等高问题的第一步是把能分离的破开。方法是每列用两个 div 替代原来的一个。第一个 div 用来放内容，另一个用来作背景色。分离使我们可以单独控制这些额外的元素，之后用更有效的方法把它们放在一起。答案呼之欲出。</p>
<p><strong>浮动的容器的高度始终取决于其浮动的内容（高度）</strong></p>
<p>这是本文多列等高方法的核心。 使一个 div 的高度等于最高列高度的唯一方法是这个 div 包含所有的列。换句话说，通过把所有的列放在一个容器中，容器的高度就是最高列的高度。这是个非常有用的结构。</p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-container-div.gif" alt="" /><br />
<strong>3列 HTML div 结构</strong></p>
<p>上例中 3 个内容列在一个 div 容器中。</p>
<pre><code>&lt;div id="container1"&gt;
    &lt;div id="col1"&gt;Column 1&lt;/div&gt;
    &lt;div id="col2"&gt;Column 2&lt;/div&gt;
    &lt;div id="col3"&gt;Column 3&lt;/div&gt;
&lt;/div&gt;</code></pre>
<p><strong>3 列 CSS</strong></p>
<p>下面是使 div 容器等高于最高列的 CSS。</p>
<pre><code>#container1 {
    float:left;
    width:100%;
}
#col1 {
    float:left;
    width:30%;
    background:red;
}
#col2 {
    float:left;
    width:40%;
    background:yellow;
}
#col3 {
    float:left;
    width:30%;
    background:green;
}</code></pre>
<p>为了让这一结构在所有浏览器中正确工作，容器 div 必须浮动（左或右），同时每一个内容列的 div 也要浮动，哪种方式并不重要。浮动内容 div 的进程使它们在页面中排列在一条水平线上。浮动容器使其自适应到最高列的高度。如果不浮动容器，内容 div 将会从容器底部溢出，容器不会拥有正确的高度。事实上在此例中，容器不浮动的话其最终高度为0。</p>
<p><strong>增加额外嵌套的容器</strong></p>
<p>下一步是增加额外的容器，它们彼此嵌套。我们需要容器的数量等于列的数量：3。这 3 个容器用作各列的背景。请注意，我们去除了原始列的背景色，并将其加至容器上。</p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-3-containers.gif" alt="" /><br />
<strong>3列 HTML div 结构</strong></p>
<p>两个额外的容器加至下面的 HTML 中。</p>
<pre><code><strong>&lt;div id="container3"&gt;
    &lt;div id="container2"&gt;</strong>
        &lt;div id="container1"&gt;
            &lt;div id="col1"&gt;Column 1&lt;/div&gt;
            &lt;div id="col2"&gt;Column 2&lt;/div&gt;
            &lt;div id="col3"&gt;Column 3&lt;/div&gt;
        &lt;/div&gt;
    <strong>&lt;/div&gt;
&lt;/div&gt;</strong></code></pre>
<p><strong>3 列 CSS</strong></p>
<p>所有元素左浮动，容器宽度设为100%，使他们占满页面的宽度。背景色从内容 div 移除并加至容器上。</p>
<pre><code><strong>#container3 {
    float:left;
    width:100%;
    background:green;
}
#container2 {
    float:left;
    width:100%;
    background:yellow;
}</strong>
#container1 {
    float:left;
    width:100%;
    <strong>background:red;</strong>
}
#col1 {
    float:left;
    width:30%;
}
#col2 {
    float:left;
    width:40%;
}
#col3 {
    float:left;
    width:30%;
}</code></pre>
<p><strong>用相对定位移动容器</strong></p>
<p>现在用相对定位把容器移至新的位置。移动后 div 如下图所示。即等高列背景容器的层叠和位置。为了显示右侧的绿色列 container2 向左移了30%，为了显示中间的黄色列 container1 向左移动了40%，与此同时红色部分依然可见作为左侧列。</p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-container-positions.gif" alt="" /><br />
<strong>相对定位的 CSS</strong></p>
<p>下面是添加了相对定位的CSS。</p>
<pre><code>#container3 {
    float:left;
    width:100%;
    background:green;
}
#container2 {
    float:left;
    width:100%;
    background:yellow;
    <strong>position:relative;
    right:30%;</strong>
}
#container1 {
    float:left;
    width:100%;
    background:red;
    <strong>position:relative;
    right:40%;</strong>
}
#col1 {
    float:left;
    width:30%;
}
#col2 {
    float:left;
    width:40%;
}
#col3 {
    float:left;
    width:30%;
}</code></pre>
<p><strong>将每列的内容移回</strong></p>
<p>下一步是把每列的内容移回到页面上，使之排列在下面的背景色上。再次使用简单的相对定位来完成它。</p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-content-position.gif" alt="" /><br />
最后在最外面的容器 container3 上添加<code>overflow:hidden</code>，砍去超出容器的部分。</p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-complete.gif" alt="" /><br />
<strong>相对定位的 CSS</strong></p>
<p>下面是增加了相对定位和溢出的 CSS 规则。请注意 container3 上额外的<code>position:relative</code>; 这是为了解决一个 IE bug ，阻止<code>overflow:hidden;</code>工作。</p>
<pre><code>#container3 {
    float:left;
    width:100%;
    background:green;
    <strong>overflow:hidden;
    position:relative;</strong>
}
#container2 {
    float:left;
    width:100%;
    background:yellow;
    position:relative;
    right:30%;
}
#container1 {
    float:left;
    width:100%;
    background:red;
    position:relative;
    right:40%;
}
#col1 {
    float:left;
    width:30%;
    <strong>position:relative;
    left:70%;</strong>
}
#col2 {
    float:left;
    width:40%;
    <strong>position:relative;
    left:70%;</strong>
}
#col3 {
    float:left;
    width:30%;
    <strong>position:relative;
    left:70%;</strong>
}</code></pre>
<p><strong>对列增加 padding</strong></p>
<p>最后还需对列增加 padding，这样每列边缘的文字不至于显得拥挤。如果我们增加 padding，一些浏览器中可能正常显示，但不是所有。IE 错误的盒模型，导致其估算拥有 padding 的元素宽度异常。一个 200px 宽 20px padding 的 box 在 IE 中被视为 200px 宽，在其他浏览器中则为正确的 240px。padding 应该加在元素的宽度上。凸微软！</p>
<p>不过不用担心&#8230;我们可以用完全不依赖于 padding 的方法来解决这个问题。相反，我们把列弄窄一点（列宽减去两侧的 padding），之后用相对定位把它们移至正确的位置。在我们的例子中我们用了 2% 的 padding，则 30% 的列将减至 26%，40% 的列减至 36%。用相对定位移回列时需谨记，现在列变窄了，所以当它们一起像最初那样左浮动时，每一个需要比上一个移动更远的距离。</p>
<p><img src="http://matthewjamestaylor.com/blog/equal-height-columns-3-column-offsets.gif" alt="" /><br />
<strong>完整的CSS</strong></p>
<p>为了使布局保持在小宽度我在每个内容列增加了<code>overflow:hidden</code>; 这将切去超出列宽的东东，并阻止其干扰其他布局。重申一下，这只是 IE 的问题，其他所有浏览器会保持正确的布局，不管列内是虾米。如果你真想这样做，可以用 IE 条件注释只对 IE 写规则。</p>
<pre><code>#container3 {
    float:left;
    width:100%;
    background:green;
    overflow:hidden;
    position:relative;
}
#container2 {
    float:left;
    width:100%;
    background:yellow;
    position:relative;
    right:30%;
}
#container1 {
    float:left;
    width:100%;
    background:red;
    position:relative;
    right:40%;
}
#col1 {
    float:left;
    <strong>width:26%;
    position:relative;
    left:72%;
    overflow:hidden;</strong>
}
#col2 {
    float:left;
    <strong>width:36%;
    position:relative;
    left:76%;
    overflow:hidden;</strong>
}
#col3 {
    float:left;
    <strong>width:26%;
    position:relative;
    left:80%;
    overflow:hidden;</strong>
}</code></pre>
<p>好了，就是这样。我希望这篇文章对你有用。可以自己弄一下 CSS 看一下它是如何工作的。你可以搞很多列，只要容器和内容列的数目相等。不要忘记看看我的 demo：<a href="http://matthewjamestaylor.com/blog/equal-height-columns-2-column.htm">2 列 </a>， <a href="http://matthewjamestaylor.com/blog/equal-height-columns-3-column.htm">3 列</a>， <a href="http://matthewjamestaylor.com/blog/equal-height-columns-4-column.htm">4 列</a>，以及 <a href="http://matthewjamestaylor.com/blog/equal-height-columns-5-column.htm">5 列</a>。</div>
]]></content:encoded>
			<wfw:commentRss>http://www.iinterest.net/2009/07/14/equal-height-columns-with-cross-browser/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

