(1)两栏布局--左侧固定,右侧不固定(自适应)
①float+margin-left
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>两栏布局测试--左侧固定,右侧自适应 float+margin-left</title>
<style>
.left{
background:black;
width:200px;
float:left;
height:100vh;
}
.right{
background:orange;
margin-left:200px;
height:100vh;
}
</style>
</head>
<body>
<div class="content">
<div class="left" style="color:black"></div>
<div class="right" style="color:orange"></div>
</div>
</body>
</html>
法②:absolute
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>两栏布局--左侧固定,右侧自适应 absolute</title>
<style>
.content{
position:relative;
width:100%;
height:300px;
border:1px solid #000;
}
.left{
background:black;
width:200px;
position:absolute;
}
.right{
background:orange;
position:abosulte;
left:200px;
right:0;
}
</style>
</head>
<body>
<div class="content">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
法③:flex布局
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>两栏布局--两栏按照比例 flex布局</title>
<style>
.max{display: flex;width: 100%;height: 100vh;}
.left{flex:3;height:100%;background: red;}
.right{flex:7;height: 100%;background: blue;}
</style>
</head>
<body>
<div class="max">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
法④:table布局
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>两栏布局--两栏按照比例 table布局</title>
<style>
.box{display: table;width:100%}
.box div{
display: table-cell;
height:100vh;
}
.left{
min-width:200px;
background-color:pink;
}
.right{
width:100%;
background-color:yellow;
}
</style>
<body>
<div class="box">
<div class="left"></div>
<div class="right">
</div>
</div>
</body>
</html>