三栏布局,高度100px,左右分别宽度300px,中间部分自适应
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>页面布局</title>
</head>
<style type="text/css">
html *{
margin: 0;
padding: 0;
}
.content>div{
height: 100px;
}
.left{
width: 300px;
background: red;
float: left;
}
.right{
width: 300px;
background: blue;
float: right;
}
.center{
background: yellow;
}
.flex-box{
display: flex;
}
.left1{
width: 300px;
background: red;
}
.right1{
width: 300px;
background: blue;
}
.center1{
flex: 1;
background: yellow;
}
.relative-box{
/*position: relative;*/
}
.relative-box>div{
position: absolute;
}
.left2{
left: 0;
width: 300px;
background: red;
}
.right2{
right: 0;
width: 300px;
background: blue;
}
.center2{
left: 300px;
right: 300px;
background: yellow;
}
.table-box{
display: table;
width: 100%;
}
.table-box>div{
display: table-cell;
}
.left3{
width: 300px;
background: red;
}
.right3{
width: 300px;
background: blue;
}
.center3{
background: yellow;
}
.grid-box{
display: grid;
width: 100%;
grid-template-rows: 100px;
grid-template-columns: 300px auto 300px;
}
.left4{
width: 300px;
background: red;
}
.right4{
width: 300px;
background: blue;
}
.center4{
background: yellow;
}
</style>
<body>
<h1>浮动布局(左右中布局)</h1>
<div class="float-box content">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div>
<h1>弹性布局</h1>
<div class="flex-box content">
<div class="left1"></div>
<div class="center1"></div>
<div class="right1"></div>
</div>
<h1>定位布局(左右中布局)</h1>
<div class="relative-box content">
<div class="left2"></div>
<div class="center2"></div>
<div class="right2"></div>
</div>
<h1>table布局</h1>
<div class="table-box content">
<div class="left3"></div>
<div class="center3"></div>
<div class="right3"></div>
</div>
<h1>grid网格布局</h1>
<div class="grid-box content">
<div class="left4"></div>
<div class="center4"></div>
<div class="right4"></div>
</div>
</body>
</html>