为了账号安全,请及时绑定邮箱和手机立即绑定

浮动清除问题。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{margin:0;padding:0;}
#wrap{
	background:#FFF;/*白色*/
	margin:0 auto;
	width:960px;
	}
#header{background:#09F;width:100%;}/*淡蓝色*/
#mainbody{background:#00C;width:100%;overflow:hidden;}/*深蓝色*/
.left{
	width:800px;
	height:200px;
	background:#000;
	float:left;
	}
	
.right{
	width:140px;
	height:500px;
	background:#9F0;
	float:right;
	}
#footer{
	background:#F0F;
	width:100%;
	}/*粉红色*/
</style>
</head>

<body>
<div id="wrap">
	<div id="header">头部</div>
    <div id="mainbody">
    	<div class="left"></div>
        <div class="right"></div>
    </div>
    <div id="footer">版权部分</div>
<div>
</body>
</html>

如果我给mainbody设置一个固定高度,比如设置height=500px,这里显示就正常了,不会对后面的footer造成影响。否则就会出现如上问题,需要加overflow:hidden清除浮动。这是为什么呢?

正在回答

1 回答

当mainbody没有设置固定高度,因为被子块浮动影响导致mainbody被压缩成一条线。那么footer只能跟随right后面。

当mainbody设置固定高度后,字块影响消逝,footer跟随在mainbody后面了。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
网页布局基础
  • 参与学习       214672    人
  • 解答问题       1833    个

让你精通CSS中三大定位机制,彻底掌握网页布局的相关知识

进入课程

浮动清除问题。

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号