<?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>浮山狼de博客 &#187; float</title>
	<atom:link href="https://www.fushanlang.com/tag/float/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fushanlang.com</link>
	<description>next station - 下一站，活在当下，且行且思</description>
	<lastBuildDate>Sat, 29 Nov 2014 15:14:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.5</generator>
	<item>
		<title>css之float略解</title>
		<link>https://www.fushanlang.com/css-of-the-float-slightly-solutions-540/</link>
		<comments>https://www.fushanlang.com/css-of-the-float-slightly-solutions-540/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 09:39:16 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[float]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=540</guid>
		<description><![CDATA[ <p>css布局中常用的float样式，给我们带来非常丰富的布局，同时也给不熟悉它的人带来了许多浏览器兼容的麻烦。我这里根据自己的一些经验做些总结，希望对遇到问题的人有所帮助。</p> <p>1.浮动元素不占任何正常文档流空间，而浮动元素的定位还是基于正常的文档流，然后从文档流中抽出并尽可能远的移动至左侧或者右侧。文字内容会围绕在浮动元素周围。当一个元素从正常文档流中抽出后，仍然在文档流中的其他元素将忽略该元素并填补他原先的空间。普通的块级元素处在浮动元素下层，但它内部的文字（以及行内元素）会环绕浮动元素。</p> <p>所以使用时某个父节点如div中两个float:left的子元素，如果这个div没有定义一个限定高度，那么子float元素不对自动撑开父div，除非在换行出强制加了“clear:both”的 div来结束float流,重新将页面布局倒入下一行.由于要加入一个空div,&#60;div style=”clear:both”&#62;&#60;/div&#62; 觉得语义不好,可以有一个折中的解决方案.</p> .clearfix:after { &#160;&#160;&#160;&#160;content: “.”; &#160;&#160;&#160;&#160;display: block; &#160;&#160;&#160;&#160;height: 0; &#160;&#160;&#160;&#160;clear: both; &#160;&#160;&#160;&#160;visibility: hidden; }/*css 伪类*/ * html .clearfix {height: 1%;}/*IE hack*/ <p>这样在调用float的父节点div可以添加clearfix类来自动完成clear避免了添加无意义的空div.</p> <p>2. 浮动出现时,还有一种方法,可以不必非得添加过多的clear DIV来达到float 的布局效果.可以定义父节点Div的高度,来调节一下,以及相应的float元素的宽度.</p> <p>以下是一个例子.</p> #layout_header{ height:50px; background-color:#3C6; } #layout_body{ background-color:#09F; } #layout_footer{ background-color:#F8F05A; height:20px; } .body-left{ float:left; } .clr{ clear:both; } #body_header{ background-color:#CF0; border:solid 2px <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/css-of-the-float-slightly-solutions-540/">css之float略解</a></span>]]></description>
				<content:encoded><![CDATA[<div id="content_div-540">
<p>css布局中常用的float样式，给我们带来非常丰富的布局，同时也给不熟悉它的人带来了许多浏览器兼容的麻烦。我这里根据自己的一些经验做些总结，希望对遇到问题的人有所帮助。</p>
<p>1.浮动元素不占任何正常文档流空间，而浮动元素的定位还是基于正常的文档流，然后从文档流中抽出并尽可能远的移动至左侧或者右侧。文字内容会围绕在浮动元素周围。当一个元素从正常文档流中抽出后，仍然在文档流中的其他元素将忽略该元素并填补他原先的空间。普通的块级元素处在浮动元素下层，但它内部的文字（以及行内元素）会环绕浮动元素。</p>
<p>所以使用时某个父节点如div中两个float:left的子元素，如果这个div没有定义一个限定高度，那么子float元素不对自动撑开父div，除非在换行出强制加了“clear:both”的 div来结束float流,重新将页面布局倒入下一行.由于要加入一个空div,&lt;div style=”clear:both”&gt;&lt;/div&gt; 觉得语义不好,可以有一个折中的解决方案.</p>
<ul>
<li>
<div>.clearfix:after {</div>
</li>
<li>
<div>&nbsp;&nbsp;&nbsp;&nbsp;content: “.”;</div>
</li>
<li>
<div>&nbsp;&nbsp;&nbsp;&nbsp;display: block;</div>
</li>
<li>
<div>&nbsp;&nbsp;&nbsp;&nbsp;height: 0;</div>
</li>
<li>
<div>&nbsp;&nbsp;&nbsp;&nbsp;clear: both;</div>
</li>
<li>
<div>&nbsp;&nbsp;&nbsp;&nbsp;visibility: hidden;</div>
</li>
<li>
<div>}/*css 伪类*/</div>
</li>
<li>
<div>* html .clearfix {height: 1%;}/*IE hack*/</div>
</li>
</ul>
<p>这样在调用float的父节点div可以添加clearfix类来自动完成clear避免了添加无意义的空div.</p>
<p>2. 浮动出现时,还有一种方法,可以不必非得添加过多的clear DIV来达到float 的布局效果.可以定义父节点Div的高度,来调节一下,以及相应的float元素的宽度.</p>
<p>以下是一个例子.</p>
<style type="text/css">
#layout_header{
height:50px;
background-color:#3C6;
}
#layout_body{
background-color:#09F;
}
#layout_footer{
background-color:#F8F05A;
height:20px;
}
.body-left{
float:left;
}
.clr{
clear:both;
}
#body_header{
background-color:#CF0;
border:solid 2px white;
height:30px;
}
#body_content{
background-color:#06C;&lt;/p&gt;
&lt;p&gt;}
#body_footer{
background-color:#0FC;
height:20px;
}
.left{
float:left;
}
</style>
<div id="layout_header">layout-header</div>
<div id="layout_body">
<div style="width: 30%;" class="body-left">
<div style="background-color: rgb(102, 51, 51); width: 20%;" class="left">0</div>
<div style="background-color: rgb(204, 51, 51); width: 49%;" class="left">1</div>
<div style="background-color: rgb(0, 51, 51); width: 30%;" class="left">2</div>
<div style="background-color: rgb(34, 51, 51); width: 20%;" class="left">0</div>
<div style="background-color: rgb(68, 51, 51); width: 49%;" class="left">1</div>
<div style="background-color: rgb(136, 51, 51); width: 30%;" class="left">2</div>
<div>
<div style="background-color: rgb(102, 102, 51); width: 30%;" class="left">0</div>
<div style="background-color: rgb(170, 51, 51); width: 49%;" class="left">1</div>
<div style="background-color: rgb(0, 136, 51); width: 20%;" class="left">2</div>
</div>
<div>
<div style="background-color: rgb(102, 51, 0); width: 10%;" class="left">0</div>
<div style="background-color: rgb(204, 51, 34); width: 49%;" class="left">1</div>
<div style="background-color: rgb(0, 119, 51); width: 40%;" class="left">2</div>
</div>
</div>
<div style="background-color: rgb(0, 102, 51); width: 70%;" class="body-left">
<div id="body_header">
<div style="width: 20%;" class="left">header 0</div>
<div style="background-color: rgb(204, 51, 51); width: 59%;" class="left">header 1</div>
<div style="background-color: rgb(0, 51, 51); width: 20%; color: white;" class="left">header 2</div>
</div>
<div id="body_content">
<table>
<tbody>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
<tr>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
<td>colum0</td>
</tr>
</tbody>
</table>
</div>
<div id="body_footer">body-footer</div>
</div>
<div style="clear: both;"></div>
</div>
<div id="layout_footer">layout-footer</div>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/css-of-the-float-slightly-solutions-540/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.626 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2026-05-16 17:54:24 -->
