-
Notifications
You must be signed in to change notification settings - Fork 28
/
4-2.html
83 lines (73 loc) · 1.86 KB
/
4-2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>4.2flex布局中元素整体居左,最后几个居右</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
display: flex;
width: 600px;
padding: 10px;
margin: 50px auto;
border: 2px solid rgb(240, 103, 103);
background: rgba(103, 164, 243, .6);
}
.item {
margin-right: 30px;
font-size: 20px;
}
.item:last-child {
margin-right: 0;
}
h3 {
text-align: center;
}
/* 整体居左,最后几个居右 */
.i1:nth-last-child(1) {
margin-left: auto;
}
/* 整体居右,前几个居左 */
.c2 {
justify-content: flex-end;
}
.i2:nth-child(2) {
margin-right: auto;
}
/* 某几个居中 */
.i3:nth-child(3) {
margin-left: auto;
}
.i3:nth-child(4) {
margin-right: auto;
}
</style>
</head>
<body>
<h3>整体居左,最后几个居右</h3>
<div class='container'>
<div class='item i1'>第一项</div>
<div class='item i1'>第二项</div>
<div class='item i1'>第三项</div>
<div class='item i1'>第四项</div>
<div class='item i1'>最后一项</div>
</div>
<h3>整体居右,前几个居左</h3>
<div class='container c2'>
<div class='item i2'>第一项</div>
<div class='item i2'>第二项</div>
<div class='item i2'>第三项</div>
<div class='item i2'>第四项</div>
<div class='item i2'>最后一项</div>
</div>
<h3>某几个居中</h3>
<div class='container'>
<div class='item i3'>第一项</div>
<div class='item i3'>第二项</div>
<div class='item i3'>第三项</div>
<div class='item i3'>第四项</div>
<div class='item i3'>最后一项</div>
</div>
</body>
</html>