1.float
<!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;
}
.clearfix {
zoom: 1;
}
.clearfix::after {
display: block;
content: ' ';
clear: both
}
html,
body {
width: 100%;
height: 100%
}
.container {
width: 100%;
height: 100%;
}
.container header {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container footer {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container .left {
float: left;
}
.container .right {
float: right;
}
.container .middle {
height: calc(100% - 80px - 80px);
}
.container .middle aside {
height: 100%;
width: 300px;
background: rgba(156, 154, 249, 1);
}
</style>
</head>
<body>
<div class="container">
<!-- 顶部Header -->
<header>这里是头部</header>
<!-- 中间aside及content -->
<div class="middle clearfix">
<aside class="left"></aside>
<aside class="right"></aside>
<!-- 中间content显示内容 为了防止将右侧挤下去故放置在右侧栏下方 -->
<div class="content">这里是内容</div>
</div>
<!-- 底部Footer -->
<footer></footer>
</div>
</body>
</html>
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>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%
}
.container {
width: 100%;
height: 100%;
}
.container header {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container footer {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container .middle {
position: relative;
height: calc(100% - 80px - 80px);
}
.container .content, .container aside {
position: absolute;
}
.container .left {
width: 300px;
background: rgba(156, 154, 249, 1);
left: 0;
height: 100%;
}
.container .right {
width: 300px;
background: rgba(156, 154, 249, 1);
right: 0;
height: 100%;
}
.content {
left: 300px;
right: 300px;
}
</style>
</head>
<body>
<div class="container">
<!-- 顶部Header -->
<header>这里是头部</header>
<!-- 中间aside及content -->
<div class="middle">
<aside class="left"></aside>
<div class="content">这里是内容</div>
<aside class="right"></aside>
</div>
<!-- 底部Footer -->
<footer></footer>
</div>
</body>
</html>
3. flex
<!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;
}
html,
body {
width: 100%;
height: 100%
}
.container {
width: 100%;
height: 100%;
}
.container header {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container footer {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container .middle {
display: flex;
height: calc(100% - 80px - 80px);
}
.container aside {
width: 300px;
background: rgba(156, 154, 249, 1);
}
.content {
flex: 1;
}
</style>
</head>
<body>
<div class="container">
<!-- 顶部Header -->
<header>这里是头部</header>
<!-- 中间aside及content -->
<div class="middle">
<aside class="left"></aside>
<div class="content">这里是内容</div>
<aside class="right"></aside>
</div>
<!-- 底部Footer -->
<footer></footer>
</div>
</body>
</html>
4.display:table
<!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;
}
html,
body {
width: 100%;
height: 100%
}
.container {
width: 100%;
height: 100%;
}
.container header {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container footer {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container .middle {
display: table;
width: 100%;
height: calc(100% - 80px - 80px);
}
.container aside {
width: 300px;
display: table-cell;
background: rgba(156, 154, 249, 1);
}
.content {
display: table-cell;
}
</style>
</head>
<body>
<div class="container">
<!-- 顶部Header -->
<header>这里是头部</header>
<!-- 中间aside及content -->
<div class="middle">
<aside class="left"></aside>
<div class="content">这里是内容</div>
<aside class="right"></aside>
</div>
<!-- 底部Footer -->
<footer></footer>
</div>
</body>
</html>
5.display:grid
<!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;
}
html,
body {
width: 100%;
height: 100%
}
.container {
width: 100%;
height: 100%;
}
.container header {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container footer {
height: 80px;
background: rgba(0, 0, 0, 0.5)
}
.container .middle {
display: grid;
grid-template-columns: 300px auto 300px;
height: calc(100% - 80px - 80px);
}
.container aside {
background: rgba(156, 154, 249, 1);
}
</style>
</head>
<body>
<div class="container">
<!-- 顶部Header -->
<header>这里是头部</header>
<!-- 中间aside及content -->
<div class="middle">
<aside class="left"></aside>
<div class="content">这里是内容</div>
<aside class="right"></aside>
</div>
<!-- 底部Footer -->
<footer></footer>
</div>
</body>
</html>