<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>混合布局</title>
<style>
body{ margin:0; padding:0; font-size:30px; font-weight:bold}
div{ text-align:center; line-height:50px}
.top{ height:100px;background:#9CF}
.head{ width:960px;margin:0 auto;height:100px;background:#F90}
.main{ width:960px;margin:0 auto;border:5px solid red;}
.left{ width:220px; height:600px; background:#ccc;float:left;}
.right{ width:740px; height:600px;background:#FCC; float:right}
.r_sub_left{ width:540px; height:600px; background:#9C3; float:left}
.r_sub_right{ width:200px; height:600px; background:#9FC; float:right;}
.footer{ height:50px; background:#9F9;}
</style>
</head>
<body>
<div class="top">
<div class="head">head</div>
</div>
<div class="main">清楚看到mian撑开
<div class="left">left </div>
<div class="right">
<div class="r_sub_left">sub_left</div>
<div class="r_sub_right">sub_right</div>
</div>
</div>
<div class="footer">footer</div>
</body>
</html>1.上面的代码没有给main设置高度时,而main没有内容或子元素又设置成了浮动,footer会跑到head的下面。
2.当给 main中添加内容时,如“清楚看到mian撑开”,看到了塌陷的父元素main被撑开了。
3.在footer类中添加 clear:both;看到footer回到底部;当添加的是clear:left时,没有变化,当添加的是clear:right时,底部向上挪动了内容“楚看到mian撑开”的高度。
问题:如何理解浮动?top,main,footer是并列元素,footer受main的影响,但是main的子元素left和right是如何影响footer的? clear:left和clear:right的结果不一样,footer是如何受到影响的?是只有 r_sub_right 吗?
AllySu
阳火锅
WEYN
特辣黄焖鸡
随时随地看视频慕课网APP