<?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>Key4ever&#039;s 窝 &#187; div+css</title>
	<atom:link href="http://www.key-4ever.com/tag/divcss/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.key-4ever.com</link>
	<description>务正业  --  勤思考</description>
	<lastBuildDate>Sat, 17 Dec 2011 12:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>用float精确定位div+css</title>
		<link>http://www.key-4ever.com/2010/01/float_in_css/</link>
		<comments>http://www.key-4ever.com/2010/01/float_in_css/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 14:35:14 +0000</pubDate>
		<dc:creator>Key4ever</dc:creator>
				<category><![CDATA[前端]]></category>
		<category><![CDATA[div+css]]></category>
		<category><![CDATA[float属性]]></category>
		<category><![CDATA[页面布局]]></category>

		<guid isPermaLink="false">http://www.key-4ever.com/?p=488</guid>
		<description><![CDATA[用position的relative和absolute定位div不方便改动。用float就不折腾了，长宽定义不溢出就行了，float的详细可以看这里，里面的实例更清晰。详细代码和效果如下。 &#60;-点击看大图。 看起来每个div间都有2px距离，因为定义了边框border-width:1px，等同于div外加多一个1px，所以margin、height和width计算时像做小学计算题。以下是代码部分，两个文件放在同一文件夹就行了。 css代码部分，文件名style.css body{margin:0px auto; padding:0px; text-align:center;} #all{margin:0px auto; padding:0px; width:800px; height:800px; border-style:solid; border-width:10px; background-color:#04a2e4; } #head{margin:2px 2px 1px; padding:0px; width:794px; height:195px; border-style:solid; border-width:1px; background-color:red; } #left{margin:1px 1px 1px 2px; padding:0px; float:left; height:396px; width:395px; border-style:solid; border-width:1px; background-color:yellow; } #left1{margin:2px 2px 1px; width:389px; height:193px; border-style:solid; border-width:1px; background-color:#ffffff; } #left2{margin:1px 2px 2px; width:389px; height:193px; border-style:solid; border-width:1px; [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="HTML/CSS细节" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F10%2Fwrite-the-best-html-css%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/12/17097690.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">HTML/CSS细节</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="负边距实现超级流体布局" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F10%2Fabout-negative-margins%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/08/23/2919669.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">负边距实现超级流体布局</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Opera 10 beta was released today!" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2009%2F06%2Fopera-10-beta-was-released-today%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/12/17096256.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Opera 10 beta was released today!</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="草图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2009%2F11%2Fsketch%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/12/17099599.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">草图</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>用position的<strong>relative</strong>和<strong>absolute</strong>定位div不方便改动。用float就不折腾了，长宽定义不溢出就行了，float的详细可以<a href="http://www.w3school.com.cn/css/css_positioning_floating.asp">看这里</a>，里面的实例更清晰。详细代码和效果如下。</p>
<p><a href="http://www.key-4ever.com/wp-content/uploads/2010/01/float_css.jpg"><img class="alignnone size-medium wp-image-495" title="float_css" src="http://www.key-4ever.com/wp-content/uploads/2010/01/float_css-300x299.jpg" alt="" width="300" height="299" /></a><a href="http://www.key-4ever.com/wp-content/uploads/2010/01/css_float.jpg">&lt;-</a>点击看大图。</p>
<p>看起来每个div间都有<strong>2px</strong>距离，因为定义了边框border-width:1px，等同于div外加多一个<strong>1px</strong>，所以margin、height和width计算时像做小学计算题。以下是代码部分，两个文件放在同一文件夹就行了。</p>
<p><span id="more-488"></span></p>
<p>css代码部分，文件名style.css</p>
<pre style="background-color: #eeeeee; padding: 15px;">body{margin:0px auto;
padding:0px;
text-align:center;}
#all{margin:0px auto;
padding:0px;
width:800px;
height:800px;
border-style:solid;
border-width:10px;
background-color:#04a2e4;
}

#head{margin:2px 2px 1px;
padding:0px;
width:794px;
height:195px;
border-style:solid;
border-width:1px;
background-color:red;
}

#left{margin:1px 1px 1px 2px;
padding:0px;
float:left;
height:396px;
width:395px;
border-style:solid;
border-width:1px;
background-color:yellow;
}

#left1{margin:2px 2px 1px;
width:389px;
height:193px;
border-style:solid;
border-width:1px;
background-color:#ffffff;
}

#left2{margin:1px 2px 2px;
width:389px;
height:193px;
border-style:solid;
border-width:1px;
background-color:#ffffff;
}

#right{margin:1px 2px 1px 1px;
padding:0px;
width:395px;
height:396px;
float:left;
border-style:solid;
border-width:1px;
background-color:green;
}

#foot{margin:1px 2px 2px 2px;
padding:0px;
width:794px;
height:195px;
border-style:solid;
border-width:1px;
float:left;
background-color:#7d90e5;
}</pre>
<p>html代码部分</p>
<pre style="background-color: #eeeeee; padding: 15px;">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;CSS&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="all"&gt;
&lt;div id="head"&gt;&lt;/div&gt;
&lt;div id="left"&gt;
&lt;div id="left1"&gt;&lt;/div&gt;
&lt;div id="left2"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id="right"&gt;&lt;/div&gt;
&lt;div id="foot"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;</pre>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="HTML/CSS细节" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F10%2Fwrite-the-best-html-css%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/12/17097690.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">HTML/CSS细节</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="负边距实现超级流体布局" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F10%2Fabout-negative-margins%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/08/23/2919669.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">负边距实现超级流体布局</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="免费的午餐" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2009%2F07%2Ffree-host%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/12/17096372.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">免费的午餐</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="iGoogle中国大学生创新设计大赛" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.key-4ever.com%2F2009%2F11%2Figoogle%2F&from=http%3A%2F%2Fwww.key-4ever.com%2F2010%2F01%2Ffloat_in_css%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/12/17099566.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">iGoogle中国大学生创新设计大赛</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><h2  class="related_post_title">随机日志</h2><ul class="related_post"><li>2009/06/28 -- <a href="http://www.key-4ever.com/2009/06/hometown/" title="鄉">鄉</a> (15)</li><li>2008/05/23 -- <a href="http://www.key-4ever.com/2008/05/%e6%8e%a8%e4%bb%8b%e6%96%b9%e4%be%bf%e6%98%93%e7%94%a8%e7%9a%84%e5%9b%be%e7%89%87%e6%89%b9%e9%87%8f%e5%8e%8b%e7%bc%a9%e5%b7%a5%e5%85%b7/" title="{推介}方便易用的图片批量压缩工具">{推介}方便易用的图片批量压缩工具</a> (0)</li><li>2009/07/24 -- <a href="http://www.key-4ever.com/2009/07/change/" title="change">change</a> (6)</li><li>2009/11/13 -- <a href="http://www.key-4ever.com/2009/11/sketch/" title="草图">草图</a> (5)</li><li>2010/11/25 -- <a href="http://www.key-4ever.com/2010/11/love-fanfou/" title="饭否归来">饭否归来</a> (4)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.key-4ever.com/2010/01/float_in_css/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

