一般思路–直接写
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>
.content{
overflow: hidden;
background-color: antiquewhite;
}
.content-left{
width: 200px;
height: 400px;
float: left;
background-color: rgb(178, 240, 219);
}
.content-right{
height: 200px;
margin-left: 210px;
background-color: rgb(236, 170, 170);
}
style>
head>
<body>
<div class="content">
<div class="content-left">div>
<div class="content-right">div>
div>
body>
html>
flex弹性布局实现双栏
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>flex弹性布局实现双栏title>
<style>
.content{
background-color: antiquewhite;
display: flex;
justify-content: flex-start;
}
.content-left{
background-color: rgb(178, 240, 219);
width: 100px;
}
.content-right{
background-color: rgb(236, 170, 170);
flex: 1;
}
style>
head>
<body>
<div class="content">
<div class="content-left">zuodiv>
<div class="content-right">youdiv>
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>
.wrap{
display: flex;
justify-content: space-around;
}
.left,.middle,.right{
height: 200px;
}
.left{
width: 100px;
background-color: aquamarine;
}
.middle{
width: 100%;
margin: 0 20px;
background-color: black;
}
.right{
width: 100px;
background-color: aquamarine;
}
style>
head>
<body>
<div class="wrap">
<div class="left">左侧div>
<div class="middle">中间div>
<div class="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>
.content{
background: #eee;
overflow: hidden;
padding: 20px;
height: 200px;
}
.content-left{
width: 200px;
height: 200px;
float: left;
background: coral;
}
.content-right{
width: 120px;
height: 200px;
float: right;
background: lightblue;
}
.content-center{
margin-left: 220px;
height: 200px;
background: lightpink;
margin-right: 140px;
}
style>
head>
<body>
<div class="contents">
<div class="content-left">leftdiv>
<div class="content-right">rightdiv>
<div class="content-center">centerdiv>
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>
.container{
position: relative;
}
.left,.right,.main{
height: 200px;
text-align: center;
line-height: 200px;
}
.left{
position: absolute;
top: 0;
left: 0;
width: 100px;
background-color: antiquewhite;
}
.right{
position: absolute;
top: 0;
right: 0;
width: 100px;
background-color: aquamarine;
}
.main{
margin: 0 110px;
background-color: black;
color: aliceblue;
}
style>
head>
<body>
<div class="container">
<div class="left">左边固定宽度div>
<div class="right">右边固定宽度div>
<div class="main">中间自适应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>
.left,
.right,
.main {
height: 200px;
line-height: 200px;
text-align: center;
}
.main-wrapper {
float: left;
width: 100%;
}
.main {
margin: 0 110px;
background: black;
color: white;
}
.left,
.right {
float: left;
width: 100px;
/* margin-left: -100%; */
background: green;
}
.right {
margin-left: -100px;
/* 同自身宽度 */
}
style>
head>
<body>
<div class="main-wrapper">
<div class="main">中间自适应div>
div>
<div class="left">左边固定宽度div>
<div class="right">右边固定宽度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>
.wrap{
display: grid;
width: 100%;
grid-template-columns: 300px auto 300px;
}
.left,.middle,.right{
height: 200px;
}
.left{
background-color: aqua;
}
.right{
/* width: 300px; */
background-color: antiquewhite;
}
.middle{
background-color: blue;
}
style>
head>
<body>
<div class="wrap">
<div class="left">左侧div>
<div class="middle">中间div>
<div class="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>
body {
margin: 0;
}
div {
text-align: center;
color: #fff;
}
.header,
.footer {
height: 50px;
background-color: pink;
line-height: 50px;
}
.content {
padding-left: 200px;
padding-right: 150px;
min-width: 500px;
line-height: 500px;
}
.content>div {
float: left;
height: 500px;
}
.center {
width: 100%;
background-color: mediumturquoise;
}
.left,
.right {
position: relative;
}
.left {
width: 200px;
right: 200px;
margin-left: -100%;
background-color: skyblue;
}
.right {
width: 150px;
right: -150px;
margin-left: -150px;
background-color: lightsteelblue;
}
.footer {
clear: both;
}
style>
head>
<body>
<div class="header">headerdiv>
<div class="content">
<div class="center">centerdiv>
<div class="left">leftdiv>
<div class="right">rightdiv>
div>
<div class="footer">footerdiv>
body>
html>
双飞翼布局由淘宝UED发扬,是通过浮动和定位实现三栏布局的一种方案之一
双飞翼布局的特点:
宽度
位置
<style>
body { margin: 0; }
div {
text-align: center;
color: #fff;
}
.header, .footer {
height: 50px;
background-color: pink;
line-height: 50px;
}
.content > div {
float: left;
height: 500px;
line-height: 500px;
}
.center {
width: 100%;
background-color: mediumturquoise;
}
.inner {
height: 500px;
margin-left: 200px;
margin-right: 150px;
}
.left {
margin-left: -100%;
width: 200px;
background-color: skyblue;
}
.right {
margin-left: -150px;
width: 150px;
background-color: lightsteelblue;
}
.footer {
clear: both;
}
style>
<div class="header">headerdiv>
<div class="content">
<div class="center">
<div class="inner">center-innerdiv>
<div>
<div class="left">leftdiv>
<div class="right">rightdiv>
div>
<div class="footer">footerdiv>
实现方法:
多列布局:
<style>
.content {
column-count: 3;
column-gap: 5px;
}
.content > div {
margin-bottom: 5px;
break-inside: avoid;
color: white;
}
.d1, .d5, .d7 {
height: 100px;
background-color: skyblue;
}
.d2, .d3, .d9 {
height: 200px;
background-color: mediumturquoise;
}
.d4, .d6, .d8 {
height: 300px;
background-color: lightsteelblue;
}
style>
<div class="content">
<div class="d1">1div>
<div class="d2">2div>
<div class="d3">3div>
<div class="d4">4div>
<div class="d5">5div>
<div class="d6">6div>
<div class="d7">7div>
<div class="d8">8div>
<div class="d9">9div>
div>
弹性布局:
<style>
.content {
display: flex;
}
.column {
flex: 1;
display: flex;
flex-direction: column;
margin-right: 5px;
}
.column:last-child {
margin-right: 0;
}
.content div {
margin-bottom: 5px;
color: white;
}
.d1, .d5, .d7 {
height: 100px;
background-color: skyblue;
}
.d2, .d3, .d9 {
height: 200px;
background-color: mediumturquoise;
}
.d4, .d6, .d8 {
height: 300px;
background-color: lightsteelblue;
}
style>
<div class="content">
<div class="column">
<div class="d1">1div>
<div class="d2">2div>
<div class="d3">3div>
div>
<div class="column">
<div class="d4">4div>
<div class="d5">5div>
<div class="d6">6div>
div>
<div class="column">
<div class="d7">7div>
<div class="d8">8div>
<div class="d9">9div>
div>
div>