一、两种布局的目的
使得左右两边的宽度是固定的,只有中间的部分自适应
二、双飞翼
就是将元素嵌套到父级中,控制左右外边距(margin)进行调节
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>css</title>
</head>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.main > div {
float: left;
height: 200px;
}
.left {
width: 200px;
background: red;
margin-left: -100%;
}
.right {
width: 200px;
background: blue;
margin-left: -200px;
}
.middle {
width: 100%;
background: yellow;
}
.content {
margin-left: 200px;
margin-right: 200px;
}
</style>
<body>
<div class="main">
<div class="middle">
<div class="content">中间</div>
</div>
<div class="left">左边</div>
<div class="right">右边</div>
</div>
</body>
</html>
效果图:
三、圣杯
就是将子元素嵌套到父级中,把子元素设置相对定位,控制子元素的左右内边距(padding)进行调节
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>圣杯</title>
</head>
<style type="text/css">
body {
min-width: 550px;
}
* {
margin: 0;
padding: 0;
}
.main {
height: 200px;
padding: 0 150px 0 200px;
background: greenyellow;
}
.left,
.center,
.right {
float: left;
}
.center {
width: 100%;
height: 200px;
background: red;
}
.left {
width: 200px;
height: 200px;
background: yellow;
margin-left: -100%;
position: relative;
left: -200px;
}
.right {
width: 150px;
height: 200px;
background: skyblue;
margin-left: -150px;
position: relative;
left: 150px;
}
</style>
<body>
<div class="main">
<div class="center">中</div>
<div class="left">左</div>
<div class="right">右</div>
</div>
</body>
</html>
效果图:
好了,,就到这里了!!!!