div 自适应宽度

div 自适应宽度

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
<style type="text/css">  
body {margin: 0 auto;text-align: center;}  
#container {text-align: left;background-color: green;}  
#top {height: 160px;background-color: red;}  
#middle {height: 240px;background-color: yellow;}  
#middle_left {height:240px;width: 200px;float: left;background-color: #333;}  
#middle_right {height:240px;width: 220px;float: right;background-color: #ddd;}  
/* 自适应宽度的 div:1.不要设置 width,即 width:auto ,2.不要设置 float,即 float:none,3.其div的位置应放在最后,比 float='right' 的 div 还靠后*/  
#middle_center {height:240px;background-color: #aaa;}  
#foot {height: 120px;background-color: teal;}  
.clearDiv {clear:both;}  
</style>  
</head>  
<body>  
    <div id="container">  
        <div id="top">top</div>  
        <div class="clearDiv"></div>  
        <div id="middle">  
            <!-- 居左 -->  
            <div id="middle_left">middle left</div>  
            <!-- 居右 -->  
            <div id="middle_right">middle right</div>  
            <!-- 自适应宽度的 div 应放在最后 -->  
            <div id="middle_center">middle center</div>  
        </div>  
        <div class="clearDiv"></div>  
        <div id="foot">foot</div>  
    </div>  
</body>  
</html>  
ie6 下 float 元素的空隙 问题:
 
解决方案: 
float:left; 时 _margin-right:-3px;
float:right;时 _margin-left:-3px;
转自:http://kuchaguangjie.iteye.com/blog/752234

转载于:https://www.cnblogs.com/lvlv/p/4288487.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值