本文《布局中清除浮动效果的作用》主要是解决学员的问题,就是在学习《上-(左右)-下 固定宽度且居中布局》的时候,foot部分跑到上面来了。
站长地带还原了学员的代码内容,问题效果如下图:
在《上-(左右)-下 固定宽度且居中布局》里,站长地带使用的是将外部center使用height高度设置为left、right的等高,让foot挤下去,实现预期效果,这里我们用clear属性来做。
完整代码:
<!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=gb2312" />
<title>无标题文档</title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
body{
font-family:"微软雅黑";
font-size:12px;
}
.head{
width:1000px;
margin:0 auto;
margin-bottom:10px;
height:60px;
background-color:#999;
}
.center{
width:1000px;
margin:0 auto;
margin-bottom:10px;
}
.left{
width:740px;
background-color:#999;
height:400px;
float:left;
}
.right{
width:250px;
background-color:#999;
height:400px;
float:right;
}
.clear{
clear:both;
}
.foot{
width:1000px;
margin:0 auto;
height:60px;
background-color:#999;
}
</style>
</head>
<body>
<div class="head"></div>
<div class="center">
<div class="left"></div>
<div class="right"></div>
<div class="clear"></div>
</div>
<div class="foot"></div>
</body>
</html>
说明:请看代码中红色部分,站长地带在left、right下添加了<div class="clear"></div>
并设置了对应的属性
.clear{
clear:both;
}
目的很简单,就是清除right的浮动效果,恢复标准流状态。
效果:
搞定,欢迎到站长地带学习CSS+DIV网页制作
本文链接:https://www.dnwfb.com/975.html,转载请注明出处。
评论0