一般指的是左右侧固定,中间区域自适应。
flex 布局,父元素设置 flex 布局,左右侧width 写死,中间部分设置 flex 为1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>三栏布局</title>
<style>
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
.outer {
height: 100%;
display: flex;
}
.left {
width: 200px;
height: 100%;
background-color: pink;
}
.center {
flex: 1;
background-color: purple;
}
.right {
width: 200px;
height: 100%;
background-color: deeppink;
}
</style>
</head>
<body>
<!-- 三栏布局一般指的是左右侧固定,中间区域自适应 -->
<div class="outer">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</body>
</html>
利用 定位,父元素设置 相对定位,左右侧子元素设置 绝对定位,中间部分设置 margin-left 和 margin-right
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>三栏布局</title> <style> * { margin: 0; padding: 0; } html, body { height: 100%; } .outer { height: 100%; position: relative; } .left { width: 200px; height: 100%; background-color: pink; position: absolute; left: 0; } .center { background-color: purple; height: 100%; margin-right: 200px; margin-left: 200px; } .right { width: 200px; height: 100%; background-color: deeppink; position: absolute; top: 0; right: 0; } </style> </head> <body> <!-- 三栏布局一般指的是左右侧固定,中间区域自适应 --> <div class="outer"> <div class="left">left</div> <div class="center">center</div> <div class="right">right</div> </div> </body> </html>
利用 浮动,左侧左浮动,右侧右浮动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>三栏布局</title> <style> * { margin: 0; padding: 0; } html, body { height: 100%; } .outer { height: 100%; } .left { width: 200px; height: 100%; background-color: pink; float: left; } .center { background-color: purple; height: 100%; margin-right: 200px; margin-left: 200px; } .right { width: 200px; height: 100%; background-color: deeppink; float: right; } </style> </head> <body> <!-- 三栏布局一般指的是左右侧固定,中间区域自适应 --> <div class="outer"> <div class="left">left</div> <div class="right">right</div> <div class="center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Non placeat voluptate harum eius recusandae molestias ad minima odio aliquid adipisci aspernatur, animi quam quas laudantium! Tenetur deserunt blanditiis aperiam consequatur!</div> </div> </body> </html>