左右两栏布局
HTML部分
<body>
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
CSS部分
html,body{
width: 100%;
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
}
1. 使用flex布局
.box{
width: 100%;
height: 100%;
display: flex;
}
.left{
width: 200px;
background: red;
}
.right{
flex: 1;
background: yellowgreen;
}
2. 使用float布局
.box{
width: 100%;
height: 100%;
}
.left{
width: 200px;
height: 100%;
background: red;
float: left;
}
.right{
padding-left: 200px;
height: 100%;
background: yellowgreen;
}
3. 使用绝对定位
.box{
width: 100%;
height: 100%;
position: relative;
}
.left{
width: 200px;
height: 100%;
background: red;
position:absolute;
left: 0;
}
.right{
height: 100%;
background: yellowgreen;
margin-left: 200px;
}
上下布局,上部分定宽,下面部分高度自适应
HTML部分
<body>
<div class="box">
<header></header>
<main></main>
</div>
</body>
CSS部分
html,body{
width: 100%;
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
}
.box{
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
header{
width: 100%;
height: 100px;
background: #333;
}
main{
width: 100%;
height: 100%;
background: yellowgreen;
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 0;
}