一.布局要求
二. 代码展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>浮动布局</title>
<style>
* {
margin: 0;
padding: 0;
}
.leftfloat {
float: left;
}
.rightfloat {
float: right;
}
/* 清除浮动带来的影响 */
.clearfloat::after {
content: '';
display: block;
clear: both;
}
/* 利用继承让之后的字都先水平对齐 */
/* margin的左右auto让其布局默认水平居中 */
.container {
width: 960px;
text-align: center;
margin: 0 auto;
}
.logo {
width: 200px;
margin-right: 10px;
}
.banner1 {
width: 540px;
margin-right: 10px;
}
.banner2 {
width: 200px;
}
.logo,
.banner1,
.banner2 {
height: 80px;
background-color: #ccc;
line-height: 80px;
}
/* 让文字垂直方向居中,让行高line-height的值等于该div的height */
.menu {
width: 960px;
height: 30px;
background-color: #ccc;
margin-top: 10px;
line-height: 30px;
}
.content {
margin-top: 10px;
}
.item1,
.item2 {
width: 368px;
height: 198px;
border: 1px solid black;
margin-right: 10px;
line-height: 198px;
}
.item3,
.item4,
.item5,
.item6 {
width: 178px;
height: 198px;
border: 1px solid black;
margin-top: 10px;
margin-right: 10px;
line-height: 198px;
}
.item7,
.item8,
.item9 {
width: 198px;
height: 128px;
border: 1px solid black;
line-height: 128px;
}
.item8,
.item9 {
margin-top: 10px;
}
.footer {
width: 960px;
height: 60px;
background-color: #ccc;
margin-top: 10px;
line-height: 60px;
}
</style>
</head>
<body>
<div class="container">
<!-- 头部 -->
<div class="header clearfloat">
<div class="logo leftfloat">logo</div>
<div class="banner1 leftfloat">banner1</div>
<div class="banner2 leftfloat">banner2</div>
</div>
<!-- 菜单 -->
<div class="menu">菜单</div>
<!-- 内容区 -->
<div class="content clearfloat">
<!-- 左侧内容 -->
<div class="left leftfloat">
<div class="top clearfloat">
<div class="item1 leftfloat">栏目一</div>
<div class="item2 leftfloat">栏目二</div>
</div>
<div class="bottom clearfloat">
<div class="item3 leftfloat">栏目三</div>
<div class="item4 leftfloat">栏目四</div>
<div class="item5 leftfloat">栏目五</div>
<div class="item6 leftfloat">栏目六</div>
</div>
</div>
<!-- 右侧内容 -->
<div class="right rightfloat">
<div class="item7">栏目七</div>
<div class="item8">栏目八</div>
<div class="item9">栏目九</div>
</div>
</div>
<!-- 底部 -->
<div class="footer">页脚</div>
</div>
</body>
</html>
三.网页效果