Achieving a Dynamic Four-Column Layout
The first thing we'll do is create a grid that always covers the full viewport.
We can do that by adding a position
of fixed
and add the inset-0
class.
Let's give it a background color of bg-red-500
, just to confirm that we are covering the full viewport:
.
0:43 Before our four columns appear, we need to create elements for these. The first one will be bg-cyan-400, second one will be bg-cyan-500, and then 600, and 700.
0:56 With that in place, you can see our four grid columns, and if I resize the browser, they will always be equal width, but check what happens to our card here. The side panel is on the left, the main on the right, but when we reach a specific breakpoint, the side panel will be on the top. This happens at this custom 480px min-width breakpoint.
1:16 We only want our background color split effect when the card is side-by-side, so we can have this vertical split.
1:21 What we're going to do is completely hide this entire block of HTML below the 480px breakpoint. I can add the class by default of hidden, and then switch to display grid at the min-480px breakpoint. Below that breakpoint, the bg-cyan-500 of the parent elements takes over, and when we reach the 480px breakpoint, you can see that our four column grid appears.
1:47 That's perfect, and we're ready to move on to the next lesson.