-
Notifications
You must be signed in to change notification settings - Fork 3
/
左边固定,右边自适应.html
129 lines (111 loc) · 3.1 KB
/
左边固定,右边自适应.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!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">
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/8.0.1/normalize.css">
<title>左边固定,右边自适应</title>
<style>
.left {
width: 200px;
background: yellow;
}
.right {
background: blue;
}
.father {
background: grey;
}
/* flex布局 */
.flex {
display: flex;
height: 200px;
}
.right1 {
flex: 1;
}
/* grid 布局 */
.grid {
display: grid;
grid-template-columns: 200px calc(100% - 200px);
height: 200px;
}
/* 双子元素 + absolute */
.absolute1 {
position: relative;
height: 200px;
}
.left3 {
position: absolute;
height: 200px;
}
.right3 {
position: absolute;
left: 200px;
width: calc(100% - 200px);
height: 200px;
}
/* 左元素 absolute + 右元素 margin-left */
.absolute2 {
position: relative;
height: 200px;
}
.left4 {
position: absolute;
height: 200px;
}
.right4 {
width: calc(100% - 200px);
height: 200px;
margin-left: 200px;
}
/* 无父元素 + 左元素左浮动,右元素右浮动 */
.left5 {
float: left;
height: 200px;
}
.right5 {
height: 200px;
}
/* 无父元素 + 左元素左浮动,右元素有浮动 */
.left6 {
float: left;
height: 200px;
}
.right6 {
float: right;
height: 200px;
width: calc(100% - 200px);
}
</style>
</head>
<body>
<p>1.flex布局</p>
<div class="father flex">
<div class="left left1"></div>
<div class="right right1"></div>
</div>
<p>2.grid布局</p>
<div class="father grid">
<div class="left left2"></div>
<div class="right right2"></div>
</div>
<p>3.双子元素 + absolute</p>
<div class="father absolute1">
<div class="left left3"></div>
<div class="right right3"></div>
</div>
<p>4.左元素 absolute + 右元素 margin-left </p>
<div class="father absolute2">
<div class="left left4"></div>
<div class="right right4"></div>
</div>
<p>5.无父元素 + 左元素左浮动,右元素不动</p>
<div class="left left5"></div>
<div class="right right5"></div>
<p>6.无父元素 + 左元素左浮动,右元素右浮动</p>
<div class="left left6"></div>
<div class="right right6"></div>
</body>
</html>