-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-subgrid-example.css
More file actions
210 lines (181 loc) · 4.99 KB
/
css-subgrid-example.css
File metadata and controls
210 lines (181 loc) · 4.99 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
Copyright (c) 2020 - present, DITDOT Ltd. - MIT Licence
https://www.ditdot.hr/en
https://github.com/ditdot-dev/css-subgrid-example
*/
html {
font-size: 12px;
font-size: clamp(11px, 3vw, 14px);
/* define flexible rem size */
font-family: Roboto, Arial, sans-serif;
line-height: 1.4;
}
body {
background-color: #EEF3F6;
color: #222;
margin: 0;
}
/* MAIN GRID */
.cards-container {
max-width: 1400px;
margin: 2rem auto;
width: 95%;
display: grid;
/* set display to grid to create the outer grid */
grid-template-columns: repeat(3, [col-start] fit-content(9rem));
/* create 4 explicit column tracks */
grid-auto-rows: fit-content(12rem) minmax(10rem, 14rem) auto auto;
/* create 4 implicit row tracks */
gap: 0.5rem;
/* create the gap between grid columns and rows */
justify-content: center;
}
/* SUBGRID */
.card {
grid-column: span 3;
/* every card spans across 3 columns of the main grid */
grid-row: span 4;
/* every card spans across 4 rows of the main grid */
display: grid;
/* set display to grid in order to create a subgrid */
grid-template-columns: subgrid [card-start][button-start][col][card-end button-end];
/* create subgrid for columns to use grid column tracks of the parent and name the column lines*/
grid-template-rows: subgrid [title-start][title-end photo-start] [photo-end text-start] [text-end button-start] [button-end];
/* create subgrid for rows to use row column tracks of the parent and name the row lines*/
row-gap: 0;
/* override the inherited row gap */
background-color: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
margin: 0 0.5rem 1rem 0.5rem;
padding: 1rem;
/*padding influences the sizing of rows and columns*/
}
/* SUBGRID IN SUBGRID */
.card-header-wrapper {
grid-column: card;
/* use named tracks to place elements inside the subgrid */
grid-row: title;
display: grid;
/* make it grid container to create another subgrid inside */
grid-template-columns: subgrid;
/* create subgrid for columns to use grid column tracks of the parent */
grid-template-rows: fit-content(6rem) fit-content(6rem);
/* create two independent rows */
grid-template-areas:
"subtitle subtitle avatar"
"title title title";
/* create named grid areas to place the header elements*/
align-items: end;
font-family: "Open Sans", Arial, sans-serif;
}
/* CARD DETAILS */
.card-title {
grid-area: title;
/* place card title in the named grid area*/
font-size: 1.25rem;
}
.card-subtitle {
grid-area: subtitle;
font-weight: normal;
margin: 0;
}
.card-avatar-wrapper {
grid-area: avatar;
align-self: start;
justify-self:end;
}
.card-avatar {
object-fit: cover;
width: 3.5rem;
height: 3.5rem;
border-radius: 50%;
}
.card-photo-wrapper {
grid-column: card;
grid-row: photo;
margin-bottom: 0.5rem;
}
.card-photo {
object-fit: cover;
width: 100%;
height: 100%;
}
.card-text {
grid-column: col-start / span 3;
/* use main grid line names*/
grid-row: text;
margin-bottom: 2rem;
}
.card-like {
grid-column: 1/2;
grid-row: button;
width: 2.5rem;
height: 2.5rem;
align-self: end;
cursor: pointer;
}
.card-button {
grid-area: button;
min-width: 4rem;
height: 3rem;
background-color: #66A9D6;
border: none;
border-radius: 0.25rem;
padding: 0 0.75rem;
color: white;
font-size: 0.9rem;
text-transform: uppercase;
letter-spacing: 0.09rem;
cursor: pointer;
justify-self: end;
overflow: hidden;
text-overflow: ellipsis;
max-width: 8rem;
}
p.caption {
text-align: center;
font-size: 13px;
padding-bottom: 30px;
}
p.caption a {
color: #0086B3;
}
/* browsers without support for the subgrid feature */
@supports not (grid-template-columns: subgrid) {
.card {
grid-template-columns: repeat(3, [col-start] fit-content(9rem));
grid-template-rows: 9rem 15rem auto auto;
}
.card-header-wrapper,
.card-photo-wrapper,
.card-text {
grid-column: 1/-1;
grid-row: span 1;
}
.card-text {
margin-bottom: 0;
}
.card-button {
grid-column: 3/-1;
align-self: end;
}
}
@media screen and (min-width: 480px){
html {
font-size: clamp(11px, 2vw, 14px);
}
.cards-container {
grid-template-columns: repeat(6, [col-start] fit-content(9rem));
}
}
@media screen and (min-width: 1024px){
html {
font-size: clamp(11px, 1vw, 14px);
}
.cards-container {
grid-template-columns: repeat(12, [col-start] fit-content(9rem));
}
}
/*
This example is not supported in Internet Explorer
*/