伸缩盒模型key:flex属性。flex属性是CSS3中新增的属性,不支持IE8及以下,所以如果要兼容低版本的浏览器须用float和margin传统的布局方式
实现效果1:两边固定宽度的侧栏悬浮在两侧,中间自适应宽度1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css" media="screen">
*{
margin: 0;
padding: 0;
font-family: "微软雅黑";
}
.container{
width: 100%;
display: flex;
}
.aside{
flex-basis: 200px;
height: 500px;
background: green;
}
.main{
flex: 1;
height: 500px;
background: blue;
}
</style>
</head>
<body>
<div class="container">
<aside class="aside">aside_left</aside>
<main class="main">main</main>
<aside class="aside">aside_right</aside>
</div>
</body>
</html>
实现效果2:两边宽度自适应的侧栏悬浮在两侧,中间自适应宽度1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css" media="screen">
*{
margin: 0;
padding: 0;
font-family: "微软雅黑";
}
.container{
width: 100%;
display: flex;
}
.aside{
flex: 1;
height: 500px;
background: green;
}
.main{
flex: 5;
height: 500px;
background: blue;
}
</style>
</head>
<body>
<div class="container">
<aside class="aside">aside_left</aside>
<main class="main">main</main>
<aside class="aside">aside_right</aside>
</div>
</body>
</html>