1
00:00:02,090 --> 00:00:05,300
So let's now work on presenting our products

2
00:00:05,300 --> 00:00:07,480
appropriately in that product grid,

3
00:00:07,480 --> 00:00:10,593
and let's make it a product grid to begin with.

4
00:00:11,730 --> 00:00:12,920
Now, for that,

5
00:00:12,920 --> 00:00:14,800
we need to work on the styling

6
00:00:14,800 --> 00:00:18,260
that we apply to that product item article,

7
00:00:18,260 --> 00:00:20,220
which has a class of product-item.

8
00:00:20,220 --> 00:00:23,820
And we need to work on the styling of that unordered list,

9
00:00:23,820 --> 00:00:26,620
where we output all the products.

10
00:00:26,620 --> 00:00:30,830
For that, I will add a new CSS file in the public folder,

11
00:00:30,830 --> 00:00:32,040
in the styles folder,

12
00:00:32,040 --> 00:00:34,720
and that will be the products.css file.

13
00:00:34,720 --> 00:00:37,130
And I use a separate file because, of course,

14
00:00:37,130 --> 00:00:39,050
not all pages of this website

15
00:00:39,050 --> 00:00:41,940
will need the product-specific styling

16
00:00:41,940 --> 00:00:45,770
and hence, I wanna combine or save all the styles

17
00:00:45,770 --> 00:00:48,240
that affect the product items and grid

18
00:00:48,240 --> 00:00:50,050
in that dedicated file

19
00:00:50,050 --> 00:00:53,090
which can then only be included into the pages

20
00:00:53,090 --> 00:00:57,530
that are involved with showing product data or content.

21
00:00:57,530 --> 00:01:00,000
Now let's start with the product items.

22
00:01:00,000 --> 00:01:01,420
So with the articles

23
00:01:01,420 --> 00:01:04,173
that have this product-item class on them.

24
00:01:05,090 --> 00:01:07,060
In products.css,

25
00:01:07,060 --> 00:01:11,773
I will simply select this product-item class, like this.

26
00:01:12,630 --> 00:01:16,490
And then of course, you can apply your favorite styles.

27
00:01:16,490 --> 00:01:18,667
I will simply give those product items

28
00:01:18,667 --> 00:01:21,310
a little bit of padding

29
00:01:21,310 --> 00:01:23,643
of let's say space-4.

30
00:01:24,860 --> 00:01:27,810
I wanna give them rounded corners

31
00:01:27,810 --> 00:01:30,450
with border-radius-small,

32
00:01:30,450 --> 00:01:33,483
or actually let's go for medium here.

33
00:01:35,310 --> 00:01:37,530
I will ensure that all the text is centered

34
00:01:37,530 --> 00:01:39,643
in there with text-align: center,

35
00:01:40,520 --> 00:01:44,800
and I'll give them a background color of color-gray-600,

36
00:01:44,800 --> 00:01:48,223
which is a different gray than my page has as a background.

37
00:01:49,210 --> 00:01:52,430
Now, I also want to target the image in there specifically

38
00:01:52,430 --> 00:01:55,000
because obviously that's way too big,

39
00:01:55,000 --> 00:01:56,680
this image in the product-item.

40
00:01:56,680 --> 00:02:00,400
And there, I wanna ensure that this image

41
00:02:00,400 --> 00:02:03,970
in my product-item article actually has a width

42
00:02:03,970 --> 00:02:08,090
that's 100% of the size of the product item

43
00:02:10,120 --> 00:02:12,623
and a height of 10rem.

44
00:02:13,860 --> 00:02:16,890
I'll also give it a object-fit of cover to ensure that

45
00:02:16,890 --> 00:02:20,313
it's cropped appropriately so that it's not distorted.

46
00:02:21,680 --> 00:02:24,240
Now of course, with 100% on the image,

47
00:02:24,240 --> 00:02:26,760
won't have any effect if the product-item

48
00:02:26,760 --> 00:02:29,230
has no fixed width though.

49
00:02:29,230 --> 00:02:31,180
Now we could give product-item a width,

50
00:02:31,180 --> 00:02:33,270
but I will actually not do that.

51
00:02:33,270 --> 00:02:37,620
Instead, I wanna give that list some style instructions

52
00:02:37,620 --> 00:02:41,870
to turn it into a grid where every cell of that grid

53
00:02:41,870 --> 00:02:44,583
should then have a fixed width and height.

54
00:02:46,620 --> 00:02:49,590
So therefore, I'll give this unordered list here,

55
00:02:49,590 --> 00:02:51,800
actually, a class of product-grid

56
00:02:54,280 --> 00:02:56,300
or products-grid,

57
00:02:56,300 --> 00:02:59,490
or actually we can, of course, also go for an id,

58
00:02:59,490 --> 00:03:01,850
since we will never have more than one item

59
00:03:01,850 --> 00:03:03,623
with that id on the same page.

60
00:03:04,870 --> 00:03:06,090
And then here,

61
00:03:06,090 --> 00:03:09,100
maybe at the top of this products.css file,

62
00:03:09,100 --> 00:03:12,660
though the exact position does not matter as so often,

63
00:03:12,660 --> 00:03:14,510
I will target product-grid,

64
00:03:14,510 --> 00:03:16,360
this id just added.

65
00:03:16,360 --> 00:03:18,250
And then there, it gives us a margin

66
00:03:18,250 --> 00:03:21,680
of let's say space-8 top and bottom

67
00:03:21,680 --> 00:03:23,423
and auto left and right,

68
00:03:24,670 --> 00:03:26,530
and set the display to grid.

69
00:03:26,530 --> 00:03:28,410
That's very important.

70
00:03:28,410 --> 00:03:31,290
And we did introduce you to the grid layout

71
00:03:31,290 --> 00:03:32,510
early in the course.

72
00:03:32,510 --> 00:03:35,350
So definitely check out those lectures again,

73
00:03:35,350 --> 00:03:38,480
if you're not sure what the CSS grid is.

74
00:03:38,480 --> 00:03:41,340
Just like Flexbox, it's a layouting mechanism

75
00:03:41,340 --> 00:03:45,200
built into CSS that helps you position and size

76
00:03:45,200 --> 00:03:49,633
child elements of that element that has display: grid.

77
00:03:50,760 --> 00:03:53,230
Now one important CSS property

78
00:03:53,230 --> 00:03:56,330
which you can set in conjunction with the grid

79
00:03:56,330 --> 00:03:59,880
is the grid-template-columns property.

80
00:03:59,880 --> 00:04:01,940
This allows you to define

81
00:04:01,940 --> 00:04:06,060
how the columns of a grid should be sized.

82
00:04:06,060 --> 00:04:08,630
Every grid is made up of columns and rows,

83
00:04:08,630 --> 00:04:10,510
and you can control both.

84
00:04:10,510 --> 00:04:12,110
If you don't control it,

85
00:04:12,110 --> 00:04:16,079
then some automatic default values will be assumed.

86
00:04:16,079 --> 00:04:18,540
But again, we shared more information on that

87
00:04:18,540 --> 00:04:20,779
in dedicated lectures.

88
00:04:20,779 --> 00:04:23,250
CSS grid can be very complex

89
00:04:23,250 --> 00:04:25,160
if you want to learn all about that.

90
00:04:25,160 --> 00:04:26,990
And that's why you can also, of course,

91
00:04:26,990 --> 00:04:29,890
dive into further resources like MDN

92
00:04:29,890 --> 00:04:32,430
or our complete CSS course,

93
00:04:32,430 --> 00:04:36,220
where we dive super deeply into CSS grid.

94
00:04:36,220 --> 00:04:38,000
Here for this example,

95
00:04:38,000 --> 00:04:40,400
I'll deliberately keep it rather simple

96
00:04:40,400 --> 00:04:42,630
because the great thing about CSS grid

97
00:04:42,630 --> 00:04:45,080
is that you can achieve great layouts

98
00:04:45,080 --> 00:04:47,623
with the rather simple settings as well.

99
00:04:48,670 --> 00:04:52,530
And here, I just wanna set the columns for my grid

100
00:04:52,530 --> 00:04:54,640
and I'll use the repeat function,

101
00:04:54,640 --> 00:04:56,540
which is built into CSS,

102
00:04:56,540 --> 00:05:00,340
to repeat the same setting for multiple columns.

103
00:05:00,340 --> 00:05:03,130
And I could then enter three, for example,

104
00:05:03,130 --> 00:05:05,180
to repeat a setting three times,

105
00:05:05,180 --> 00:05:07,740
to enforce three columns.

106
00:05:07,740 --> 00:05:11,820
But I'll actually choose the auto-fill value instead,

107
00:05:11,820 --> 00:05:14,350
which ensures that the number of columns

108
00:05:14,350 --> 00:05:17,760
that will be generated will be chosen dynamically

109
00:05:17,760 --> 00:05:20,000
and automatically by the browser

110
00:05:20,000 --> 00:05:23,050
based on the available screen width.

111
00:05:23,050 --> 00:05:25,800
And that's amazing because then I don't have to worry

112
00:05:25,800 --> 00:05:28,260
about picking the appropriate number of columns

113
00:05:28,260 --> 00:05:30,190
for different screen sizes.

114
00:05:30,190 --> 00:05:32,273
Instead, the browser will do it for me.

115
00:05:33,440 --> 00:05:35,100
The browser will do it for me

116
00:05:35,100 --> 00:05:38,580
with help of the second value I plan to repeat,

117
00:05:38,580 --> 00:05:40,640
which is a value where I define

118
00:05:40,640 --> 00:05:44,020
the size, the width of my columns.

119
00:05:44,020 --> 00:05:46,310
And I'll do that with another built-in function,

120
00:05:46,310 --> 00:05:47,743
which is called minmax.

121
00:05:48,910 --> 00:05:52,110
That's a function which itself takes two values,

122
00:05:52,110 --> 00:05:54,350
a minimum and a maximum value,

123
00:05:54,350 --> 00:05:57,790
and then the browser will size the columns appropriately

124
00:05:57,790 --> 00:05:59,240
based on their content

125
00:05:59,240 --> 00:06:01,753
and the available space in the browser.

126
00:06:03,150 --> 00:06:05,770
Now here I'll choose 15rem as a minimum value

127
00:06:05,770 --> 00:06:10,450
for my columns and one fraction as a maximum value.

128
00:06:10,450 --> 00:06:13,610
One fraction simply means that at a maximum,

129
00:06:13,610 --> 00:06:17,530
the browser may squeeze as many columns as possible

130
00:06:17,530 --> 00:06:19,060
for the given screen size,

131
00:06:19,060 --> 00:06:22,260
into a given row where all the columns

132
00:06:22,260 --> 00:06:23,860
should have the same width.

133
00:06:23,860 --> 00:06:26,623
They should have one fraction of the available width.

134
00:06:27,510 --> 00:06:30,130
The minimum width should be 15rem.

135
00:06:30,130 --> 00:06:33,140
Without that, if we just would use one fraction,

136
00:06:33,140 --> 00:06:35,920
the browser could squeeze 20 columns

137
00:06:35,920 --> 00:06:37,370
into one of the same row,

138
00:06:37,370 --> 00:06:41,530
as long as they have to same pretty small width.

139
00:06:41,530 --> 00:06:43,893
That's why I set a minimum width as well.

140
00:06:45,270 --> 00:06:46,110
Last but not least,

141
00:06:46,110 --> 00:06:48,640
I'll add the gap CSS property,

142
00:06:48,640 --> 00:06:52,210
which will define some spacing that will be used

143
00:06:52,210 --> 00:06:54,960
between the columns so that there is some blank space

144
00:06:54,960 --> 00:06:57,180
between the columns and rows.

145
00:06:57,180 --> 00:06:59,210
And here I'll use space-4,

146
00:06:59,210 --> 00:07:03,923
and gap sets spacing for both between columns and rows.

147
00:07:05,400 --> 00:07:06,710
And that is all.

148
00:07:06,710 --> 00:07:09,130
Now we just have to ensure that product.css

149
00:07:09,130 --> 00:07:10,310
will be used.

150
00:07:10,310 --> 00:07:13,730
And for that in the all-products.ejs file

151
00:07:13,730 --> 00:07:15,320
in the admin folder,

152
00:07:15,320 --> 00:07:19,720
here after including the head include,

153
00:07:19,720 --> 00:07:24,720
I will now include /styles/products.css.

154
00:07:26,230 --> 00:07:29,823
So that this CSS file is used for this page.

155
00:07:31,150 --> 00:07:32,910
With that, if you reload,

156
00:07:32,910 --> 00:07:34,993
this is how a single item looks like.

157
00:07:35,870 --> 00:07:37,490
It's not fully done yet.

158
00:07:37,490 --> 00:07:40,920
There is more to do, but this is a start.

159
00:07:40,920 --> 00:07:43,500
What I will do for example, in addition,

160
00:07:43,500 --> 00:07:45,400
is in product-item,

161
00:07:45,400 --> 00:07:48,940
I will actually add a little div here,

162
00:07:48,940 --> 00:07:52,160
a div because I have no specific semantic meaning

163
00:07:52,160 --> 00:07:53,390
that I would want to add.

164
00:07:53,390 --> 00:07:56,120
I just want to use it for styling purposes.

165
00:07:56,120 --> 00:07:57,670
And I'll move the product title

166
00:07:57,670 --> 00:07:59,763
and my actions into that div.

167
00:08:01,360 --> 00:08:03,970
I do that because then I will give this div

168
00:08:03,970 --> 00:08:08,410
a class of product-item-content.

169
00:08:08,410 --> 00:08:09,980
And I'll give this inner div,

170
00:08:09,980 --> 00:08:12,160
which holds my links and buttons,

171
00:08:12,160 --> 00:08:16,283
a class of product-item-actions, by the way.

172
00:08:17,330 --> 00:08:20,740
And I did that because, now in product.css,

173
00:08:20,740 --> 00:08:25,110
I can target the product-item-content class

174
00:08:25,110 --> 00:08:26,920
I just added.

175
00:08:26,920 --> 00:08:30,440
And it's there where I actually want to add the padding now,

176
00:08:30,440 --> 00:08:33,179
instead of the product-item itself,

177
00:08:33,179 --> 00:08:36,559
which has the advantage that now there won't be any padding

178
00:08:36,559 --> 00:08:39,620
between the box of this item and the image.

179
00:08:39,620 --> 00:08:41,030
Now the image just also

180
00:08:41,030 --> 00:08:43,460
should have to use rounded corners.

181
00:08:43,460 --> 00:08:45,980
And to enforce that on the product-item,

182
00:08:45,980 --> 00:08:48,430
where I set up the rounded corners,

183
00:08:48,430 --> 00:08:52,470
I will add overflow: hidden.

184
00:08:52,470 --> 00:08:55,950
This ensures that any content from inside this container

185
00:08:55,950 --> 00:08:58,140
that would go outside of this container

186
00:08:58,140 --> 00:09:00,540
is basically cut off.

187
00:09:00,540 --> 00:09:04,580
And that ensures that the non-rounded corners of the image

188
00:09:04,580 --> 00:09:06,373
are cut off to be rounded.

189
00:09:07,810 --> 00:09:10,460
Now, I still have the padding here for my content.

190
00:09:10,460 --> 00:09:12,544
And now of course we can work on the styling

191
00:09:12,544 --> 00:09:14,700
of that actual content,

192
00:09:14,700 --> 00:09:16,330
so the title in there,

193
00:09:16,330 --> 00:09:18,783
and of the action buttons.

194
00:09:19,740 --> 00:09:21,980
And I'll start with the title.

195
00:09:21,980 --> 00:09:24,060
In product-item-content,

196
00:09:24,060 --> 00:09:26,160
I want to target the h2 element

197
00:09:26,160 --> 00:09:28,210
that can be found in there.

198
00:09:28,210 --> 00:09:30,830
And I will give it

199
00:09:30,830 --> 00:09:34,070
a font size of 1.25rem,

200
00:09:34,070 --> 00:09:37,410
which is a bit smaller than it would otherwise have.

201
00:09:37,410 --> 00:09:41,580
And I also want to reduce the margin to space-2 0

202
00:09:41,580 --> 00:09:44,853
instead of the bigger margin which it would otherwise have.

203
00:09:45,750 --> 00:09:48,453
With that, the title is a bit smaller.

204
00:09:51,310 --> 00:09:55,023
Let's actually choose 1.15rem for the font size.

205
00:09:55,970 --> 00:09:59,370
Now, of course, the buttons also don't look good like this.

206
00:09:59,370 --> 00:10:03,220
Instead, here I want to target the

207
00:10:03,220 --> 00:10:05,410
product-item actions class

208
00:10:05,410 --> 00:10:08,110
that I added to this div that holds the anchor tag

209
00:10:08,110 --> 00:10:09,500
and the button.

210
00:10:09,500 --> 00:10:10,913
So let's target this.

211
00:10:11,870 --> 00:10:15,700
And here we can actually give this a display of flex

212
00:10:15,700 --> 00:10:18,960
to align these two items which sit in the same row,

213
00:10:18,960 --> 00:10:21,120
and add a gap here,

214
00:10:21,120 --> 00:10:23,290
which cannot just be used for the grid,

215
00:10:23,290 --> 00:10:28,200
but also for Flexbox to add spacing between the flex items

216
00:10:28,200 --> 00:10:31,193
of var space-2.

217
00:10:32,320 --> 00:10:35,833
And give this some margin to the top actually,

218
00:10:36,760 --> 00:10:41,170
of var space-4

219
00:10:41,170 --> 00:10:43,063
to have some distance to the top.

220
00:10:43,940 --> 00:10:47,683
Save this, and now we have these buttons here.

221
00:10:49,010 --> 00:10:50,270
So now this looks better.

222
00:10:50,270 --> 00:10:53,990
Now we styled this grid and the product items.

223
00:10:53,990 --> 00:10:56,310
Now it is of course time to make sure

224
00:10:56,310 --> 00:11:00,140
that we can also view and edit our products

225
00:11:00,140 --> 00:11:04,050
before we then work on the image preview for uploading,

226
00:11:04,050 --> 00:11:07,870
and we then finish all the product-related logic.

227
00:11:07,870 --> 00:11:11,090
I also briefly want to mention and emphasize

228
00:11:11,090 --> 00:11:15,070
that I do not optimize for responsive styles

229
00:11:15,070 --> 00:11:17,690
when it comes to the administration area.

230
00:11:17,690 --> 00:11:21,360
Most pages should work pretty well on smaller screens,

231
00:11:21,360 --> 00:11:23,680
but unlike for the customer facing part,

232
00:11:23,680 --> 00:11:25,744
I'm not optimizing for smaller screens

233
00:11:25,744 --> 00:11:27,600
here in the admin area,

234
00:11:27,600 --> 00:11:30,770
simply because we are the administrator

235
00:11:30,770 --> 00:11:34,240
and we will administrate from a desktop device, typically.

236
00:11:34,240 --> 00:11:36,160
So no optimizations here.

237
00:11:36,160 --> 00:11:38,580
For the customer-facing sites, we of course,

238
00:11:38,580 --> 00:11:40,720
do want to build them such that they also

239
00:11:40,720 --> 00:11:42,513
look good on smaller screens.

