1、滿屏佈局
<!DOCTYPE html>
<html>
<head>
<title>滿屏</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.container{
width:100%;
height:100%;
background:#ccc;
}
</style>
</head>
<body>
<div class="container"></div>
</body>
</html>
2、左右佈局,左邊自適應右邊寬度固定,如200px
(1)定位
<!DOCTYPE html>
<html>
<head>
<title>左右</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.left {
height: 100%;
background: #ddd;
padding-right: 200px;
}
.right {
width: 200px;
height: 100%;
background: #000;
position: absolute;
right: 0;
top: 0;
bottom: 0;
}
</style>
</head>
<body>
<div class="left"></div>
<div class="right"></div>
</body>
</html>
(2)浮動
<head>
<title>左右</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.left {
background: #ddd;
height: 100%;
}
.right {
width: 200px;
float: right;
height: 100%;
background: #000;
}
</style>
</head>
<body>
<div class="right"></div>
<div class="left"></div>
</body>
</html>
(3)flex佈局
<head>
<title>左右</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body,.container {
width: 100%;
height: 100%;
}
.container{
display:flex;
display:-webkit-flex;
}
.right{
flex:0 0 200px;
height:100%;
background:#000;
}
.left{
background:#ddd;
height:100%;
flex:1;/*div佔據所有剩餘寬度 */
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
3、左中右佈局
(1)定位
<!DOCTYPE html>
<html>
<head>
<title>左中右</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.right,.left{
position: absolute;
top: 0;
width: 200px;
bottom: 0;
z-index: 100;
background: #ddd;
border:1px solid #000;
}
.middle{
height:100%;
background:coral;
padding:0 200px 0 200px;
}
.left {
left:0;
}
.right{
right:0;
}
</style>
</head>
<body>
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</body>
</html>
(2)浮動
<!DOCTYPE html>
<html>
<head>
<title>左中右</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.left,
.right {
width: 200px;
height: 100%;
background: #ddd;
}
.left {
float: left;
}
.right {
float: right;
}
.middle {
background: #00ddff;
height: 100%;
}
</style>
</head>
<body>
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>左中右</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body,
.container {
width: 100%;
height: 100%;
}
.container{
display:flex;
}
.middle{
flex:1;
background:#ddd;
}
.left {
flex:0 0 200px;
background:#000;
}
.right {
flex:0 0 200px;
background:#000;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
</body>
</html>