Skip to content

Commit cb5d1c5

Browse files
committed
card using grid
1 parent 8067ad7 commit cb5d1c5

File tree

1 file changed

+112
-117
lines changed

1 file changed

+112
-117
lines changed

css/card.scss

+112-117
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,131 @@ $u-card-border: none;
5757
display: flex;
5858
flex-wrap: wrap;
5959

60-
// same as .col1
60+
// one column only as default
6161
width: 100%;
6262
gap: var(--card-gap); // $u-card-gap;
6363

64-
// center in container by default
64+
// center in main container by default
6565
margin: 0 auto;
6666

67+
>.card {
68+
position: relative;
69+
width: var(--card-width);
70+
height: var(--card-height);
71+
72+
// used a card grid for normal cards (not horizonal)
73+
display: grid;
74+
grid-template-columns: auto;
75+
grid-template-areas: "header" "main" "footer";
76+
grid-template-rows: auto 1fr auto;
77+
gap: 0;
78+
margin: 0;
79+
padding: 0;
80+
81+
page-break-inside: avoid;
82+
overflow: hidden;
83+
background-color: var(--card-back);
84+
border: var(--card-border);
85+
border-radius: var(--card-radius);
86+
87+
@media print {
88+
border: 1px solid base.$u-text;
89+
}
90+
91+
/* cards can be marked with class='wide' covering 2 columns */
92+
&.wide {
93+
width: calc(var(--card-width) * 2 + var(--card-gap));
94+
}
95+
96+
/* cards can be marked with class='wide' covering 2 columns */
97+
&.small {
98+
width: calc((var(--card-width) - var(--card-gap)) / 2);
99+
height: calc((var(--card-height) - var(--card-gap)) / 2);
100+
}
101+
102+
// images as first element in card
103+
>svg:first-child,
104+
>img:first-child {
105+
grid-area: header;
106+
width: 100%;
107+
height: var(--card-image-size);
108+
object-fit: cover;
109+
110+
&.icon {
111+
width: 2.75rem;
112+
height: 2.75rem;
113+
}
114+
}
115+
116+
.header {
117+
grid-area: header;
118+
background-color: var(--card-head);
119+
padding: var(--card-padding);
120+
min-height: 2.75em; // with or without icon
121+
max-height: 4rem;
122+
123+
h3,
124+
h4 {
125+
margin: 0;
126+
}
127+
128+
// images in header
129+
>svg:first-child,
130+
>img:first-child {
131+
// display: block;
132+
float: left;
133+
height: 2.75rem;
134+
aspect-ratio: 1/1;
135+
margin-right: var(--card-padding);
136+
}
137+
138+
}
139+
140+
.main,
141+
.body {
142+
grid-area: main;
143+
flex: 1;
144+
145+
/* background-color: lime; */
146+
padding: var(--card-padding);
147+
}
148+
149+
.footer,
150+
.actions {
151+
grid-area: footer;
152+
height: auto;
153+
width: 100%;
154+
padding: var(--card-padding);
155+
border-top: 1px solid rgb(0 0 0 / 12.5%);
156+
background-color: inherit;
157+
}
158+
159+
&.autolink a:first-of-type::before {
160+
position: absolute;
161+
top: 0;
162+
left: 0;
163+
height: 100%;
164+
width: 100%;
165+
content: "";
166+
}
167+
}
168+
169+
67170
// container marked with class='horizontal' for horizontal oriented cards
68171
// stretching on the whole with with image on the left */
69172
&.horizontal {
70173
--card-width: 100%;
71174
--card-height: 7.2rem;
72175

73176
>.card {
74-
// container-name: card;
75-
// container-type: inline-size;
76-
flex-direction: row;
77-
align-items: stretch;
78-
79-
>svg:first-of-type,
80-
>img:first-of-type {
81-
display: block;
82-
float: left;
83-
margin-right: var(--card-padding);
177+
grid-template-areas: "header main" "header footer";
178+
grid-template-columns: max-content auto;
179+
grid-template-rows: 1fr auto;
180+
181+
>svg:first-child,
182+
>img:first-child {
84183
width: var(--card-image-size);
85184
height: 100%;
86-
object-fit: cover;
87185
}
88186
}
89187
}
@@ -128,7 +226,7 @@ $u-card-border: none;
128226
width: calc(365px * 4 + 10px * 3);
129227

130228
// @container main (width < #{$u-card-4col}) {
131-
@container main (width <= #{365px * 4 + 10px * 3}) {
229+
@container main (width <=#{365px * 4 + 10px * 3}) {
132230
width: calc(365px * 3 + 10px * 2);
133231
}
134232

@@ -140,109 +238,6 @@ $u-card-border: none;
140238
width: 365px;
141239
}
142240
}
143-
144-
145-
// One column only.
146-
&.col1 {
147-
width: 100%;
148-
}
149-
150-
}
151-
152-
/* The cards are sized according to the given variables from :root or from the card-container) */
153-
.card {
154-
position: relative;
155-
display: flex;
156-
flex-direction: column;
157-
width: var(--card-width);
158-
height: var(--card-height);
159-
margin: 0;
160-
padding: 0;
161-
page-break-inside: avoid;
162-
overflow: hidden;
163-
background-color: var(--card-back);
164-
border: var(--card-border);
165-
border-radius: var(--card-radius);
166-
167-
@media print {
168-
border: 1px solid base.$u-text;
169-
}
170-
171-
/* cards can be marked with class='wide' covering 2 columns */
172-
&.wide {
173-
width: calc(var(--card-width) * 2 + var(--card-gap));
174-
}
175-
176-
/* cards can be marked with class='wide' covering 2 columns */
177-
&.small {
178-
width: calc((var(--card-width) - var(--card-gap)) / 2);
179-
height: calc((var(--card-height) - var(--card-gap)) / 2);
180-
}
181-
182-
// images as first element in card
183-
>svg:first-of-type,
184-
>img:first-of-type {
185-
display: block;
186-
width: 100%;
187-
height: var(--card-image-size);
188-
object-fit: cover;
189-
190-
&.icon {
191-
width: 2.75rem;
192-
height: 2.75rem;
193-
}
194-
}
195-
196-
.header {
197-
background-color: var(--card-head);
198-
padding: var(--card-padding);
199-
min-height: 2.75em; // with or without icon
200-
max-height: 4rem;
201-
202-
h3,
203-
h4 {
204-
margin: 0;
205-
}
206-
207-
// images in header
208-
>svg:first-of-type,
209-
>img:first-of-type {
210-
display: block;
211-
float: left;
212-
height: 2.75rem;
213-
aspect-ratio: 1/1;
214-
margin-right: var(--card-padding);
215-
}
216-
217-
}
218-
219-
.main,
220-
.body {
221-
flex: 1;
222-
223-
/* background-color: lime; */
224-
padding: var(--card-padding);
225-
}
226-
227-
.footer,
228-
.actions {
229-
// position: absolute;
230-
align-self: flex-end;
231-
height: auto;
232-
width: 100%;
233-
padding: var(--card-padding);
234-
border-top: 1px solid rgb(0 0 0 / 12.5%);
235-
background-color: inherit;
236-
}
237-
238-
&.autolink a:first-of-type::before {
239-
position: absolute;
240-
top: 0;
241-
left: 0;
242-
height: 100%;
243-
width: 100%;
244-
content: "";
245-
}
246241
}
247242

248243

0 commit comments

Comments
 (0)