## 两栏布局的方式
原理:利用BFC实现两栏布局
效果:实现左边固定宽度,右边自适应宽度
这里介绍两种方式:
方法一:
<!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{
height: 100%;
}
.box{
width: 100%;
height: 100%;
background: #dedede;
}
.left{
width: 200px;
height: 100%;
float: left;
background: gray;
}
.right{
height: 100%;
margin-left: 200px;
/*方法1*/
/*padding-left: 200px;*
}
</style>
</head>
<body>
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
方法二:
/* 方法三*/
<!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{
height: 100%;
}
.box{
width: 100%;
height: 100%;
background: #dedede;
}
.left{
width: 200px;
height: 100%;
float: left;
background: gray;
}
.right{
height: 100%;
margin-left: 200px;
/* 方法二*/
overflow: hidden;
float: left;
background: #000;
}
</style>
</head>
<body>
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
/*overflow: hidden;*/
/*float: left;*/
background: #000;