4. 浮动实战应用
4.1 左右两列布局

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>左右两列布局</title>
<style>
.clearfix::after {
content: "";
display: table;
clear: both;
}
.box {
width: 600px;
border: 2px solid #000;
}
.left {
width: 200px;
height: 200px;
background-color: lightblue;
float: left;
}
.right {
width: 380px;
height: 200px;
background-color: lightgreen;
float: right;
}
</style>
</head>
<body>
<div class="box clearfix">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
4.2 一行多列

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>一行多列</title>
<style>
.clearfix::after {
content: "";
display: block;
clear: both;
}
.box {
width: 600px;
border: 2px solid #000;
}
.left, .middle, .right {
height: 100%;
float: left;
}
.left {
width: 30%;
height: 200px;
background-color: lightcoral;
}
.middle {
width: 40%;
height: 200px;
background-color: lightseagreen;
}
.right {
width: 30%;
height: 200px;
background-color: lightblue;
}
</style>
</head>
<body>
<div class="box clearfix">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
</body>
</html>
4.3 三列式布局,中间自适应

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>一行多列</title>
<style>
body {
margin: 0;
}
.box {
width: 100%;
background-color: khaki;
padding: 10px;
box-sizing: border-box;
}
.box .left {
width: 150px;
height: 200px;
background-color: skyblue;
float: left;
}
.box .middle {
background-color: aquamarine;
height: 200px;
margin: 0px 160px;
}
.box .right {
width: 150px;
height: 200px;
background-color: pink;
float: right;
}
.clearfix::after {
display: block;
content: "";
clear: both;
}
</style>
<body>
<div class="box clearfix">
<div class="left">左</div>
<div class="right">右</div>
<div class="middle">中</div>
</div>
</body>
</html>
4.4 多列布局

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
width: 800px;
background-color: skyblue;
margin: 0px auto;
padding: 5px;
}
.item {
width: 190px;
height: 200px;
background-color: khaki;
float: left;
margin: 5px;
}
.clearfix::after {
display: block;
content: "";
clear: both;
}
</style>
<body>
<div class="container clearfix">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
</div>
</body>
</html>
4.5 网站布局

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,
ul {
margin: 0;
}
ul {
padding: 0;
list-style: none;
}
.clearfix::after {
display: block;
content: "";
clear: both;
}
.top {
height: 50px;
background-color: skyblue;
}
.container {
width: 1000px;
margin: 10px auto;
}
.container .header .logo {
width: 100px;
height: 120px;
background-color: pink;
float: left;
}
.container .header .nav {
width: 700px;
float: right;
}
.nav .nav-top {
width: 500px;
height: 50px;
background-color: turquoise;
float: right;
}
.nav .nav-bottom {
height: 60px;
width: 100%;
background-color: tomato;
float: right;
margin-top: 10px;
}
.main {
margin-top: 20px;
}
.main-top .main-top-menu {
width: 200px;
height: 500px;
background-color: lavender;
float: left;
}
.main-top .main-top-content {
width: 520px;
height: 500px;
float: left;
margin-left: 15px;
}
.main-top .main-top-recommend {
width: 250px;
height: 500px;
background-color: orange;
float: right;
}
.main-top-content .top-content-banner {
height: 300px;
background-color: tomato;
}
.main-top-content .top-content-hot {
height: 180px;
margin-top: 20px;
}
.top-content-hot ul li {
width: 120px;
height: 180px;
background-color: aquamarine;
margin: 0px 5px;
float: left;
}
.footer {
height: 100px;
background-color: #ddd;
}
</style>
<body>
<div class="top"></div>
<div class="container">
<div class="header clearfix">
<div class="logo"></div>
<div class="nav clearfix">
<div class="nav-top"></div>
<div class="nav-bottom"></div>
</div>
</div>
<div class="main">
<div class="main-top clearfix">
<div class="main-top-menu"></div>
<div class="main-top-content">
<div class="top-content-banner"></div>
<div class="top-content-hot">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</div>
<div class="main-top-recommend"></div>
</div>
</div>
</div>
<div class="footer"></div>
</body>
</html>