-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflexbox-practice-1.html
More file actions
72 lines (62 loc) · 1.52 KB
/
flexbox-practice-1.html
File metadata and controls
72 lines (62 loc) · 1.52 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flexbox in Practice</title>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Helvetica;
font-weight: bold;
}
.flex-container {
width: 100%;
border: 3px solid goldenrod;
display: flex;
}
.flex-item {
background: #BFD45D;
border: 2px solid #F9EFD6;
padding: 1em;
}
#container-one {
/* set the height to 200px */
height: 200px;
/* first: center this item horizontally then vertically */
}
#container-one .flex-item {
/* second: user margin to center it */
margin: auto;
/*the 1st argument is the vertical 2nd is horizontal*/
}
#container-two .flex-item:nth-of-type(3) {
/* push this item all the way to the left */
/*margin-left: auto;*/
}
#container-two .flex-item:nth-of-type(2) {
/* push item 3 all the way to the right */
/*margin-right: auto;*/
/* and then center this item using margin on both horiz. sides */
margin: 0 auto;
}
</style>
</head>
<body>
<header class="container">
<h1>Flexbox in Practice: Centering</h1>
</header>
<h4>Centering a flex item</h4>
<div id="container-one" class="flex-container">
<div class="flex-item">Item 1</div>
</div>
<h4>Margin auto</h4>
<div id="container-two" class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div class="flex-item">Item 3</div>
</div>
</body>
</html>