-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-grid-align-content.html
69 lines (64 loc) · 2.23 KB
/
4-grid-align-content.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
<!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>Grid Alignment</title>
<style>
.container {
border: 1px solid black;
background-color: lightblue;
height: 80vh;
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: minmax(50px, auto) 100px;
gap: 15px;
/*
Align grid items inside the grid container
- Sometimes the total size of your grid might be less than the size of its grid container.
- This could happen if all of your grid items are sized with non-flexible units like px.
- In this case you can set the alignment of the grid within the grid container.
- justify-content aligns the grid along the inline (row) axis
- align-content which aligns the grid along the block (column) axis).
- default = stretch; start, end, center, space-between, space-around, space-evenly
*/
justify-content: center;
align-content: space-around;
/*
Align grid items within their individual cells/tracks
- justify-items aligns grid items along the inline (row) axis, horizontally
- align-items aligns along the block (column) axis), vertically
- default = stretch
*/
justify-items: stretch;
align-items: start;
}
.item {
border: 1px solid #333;
background-color: #777;
color: yellow;
}
.item2 {
/* layout individual items, similar to flexbox */
align-self: center;
}
.item5 {
justify-self: end;
align-self: stretch;
}
</style>
</head>
<body>
<div class="container">
<div class="item item1">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
<div class="item item7">7</div>
<div class="item item8">8</div>
</div>
</body>
</html>