# Heading
html布局如下
点击查看代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./autoResize.css">
</head>
<body>
<div class="box">
<div class="a">固定宽度的一侧</div>
<div class="b">自适应的一侧</div>
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# margin + float
对固定宽度的元素设置float,自适应的一侧(块级元素)通过margin避免两元素的重叠,本质还是利用块级元素具有默认继承父元素宽度的特性。 <<<@/src/CSS/autoResize.css
# 绝对定位
对自适应元素设置absolute定位,通过left: 200px, right: 0对自适应元素进行宽度拉伸
.box{
position: relative;
}
.a{
width: 200px;
height: 200px;
background-color: aqua;
}
.b{
height: 200px;
position: absolute;
top: 0;
right: 0;
left: 200px;
background-color: greenyellow;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# flex
.box{
display: flex;
}
.a{
width: 200px;
height: 200px;
background-color: aqua;
}
.b{
height: 200px;
flex: 1;
background-color: greenyellow;
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 其他
calc( 100% - 200px )
calc( 100vw - 200px )
TODO 不知道%计算宽度为什么会有5px差距
<<<@/src/CSS/autoResize3.css