Grid layout combinations

I'm trying to recreate this reference image with css grid but i'm a little confused on the most sufficient way to lay out the grid. This is a new design style i'm trying too so it creates a little more confusion with laying it out šŸ˜… . I've attempted to draw out plans for the grid layout but i've ran into a few things that have halted me a little due to confusion, for example, in the first image, i've laid the grid out with one column and four rows but i'm unsure whether wrapping the last two images in a container or having two rows in the grid is the best way to go. When i thought about having two columns in the grid i got a little confused on how to span the top row of three items along two columns so i thought that one column along with flex to lay out the three items would be best additionally wrapping the last two images in a container but i'm honestly not sure on the best approach to this. I'm trying to decide on the best approach that also allows an easier conversion to a responsive version of the grid (as seen in the second image, which i've also attempted to draw the plan out to). Has anyone got any advice?
29 Replies
DJR
DJRā€¢17mo ago
You could use grid-template-areas and grid-area. But bear in mind any grid-gap you use will be applied throughout, so if you want the two images at the bottom to be closer than the paragraphs of text above, you might want to consider having that as one column and using flex instead for that particular row.
snxxwyy
snxxwyyā€¢17mo ago
ah yeah that makes a lot of sense now, thank you, i'll give that a go šŸ‘
DJR
DJRā€¢17mo ago
No problem. šŸ‘
snxxwyy
snxxwyyā€¢17mo ago
hey again, i hope you don't mind me asking for a pointer with this šŸ˜… , i've annotated the picture here with where i got a little stuck. This is for the tablet layout btw, i attatched a codepen incase that helps? https://codepen.io/deerCabin/pen/mdQBjag
R
CodePen
sea scape
...
snxxwyy
snxxwyyā€¢17mo ago
just realised my english in the annotation is all messed up šŸ˜…, i'll fix that..
gap here grows to the same size as the gap where the green line is as both the containers containing the items are items of the grid. should i push the picture spanning across down with margin or group all three pictures and create another grid layout of of that container?
gap here grows to the same size as the gap where the green line is as both the containers containing the items are items of the grid. should i push the picture spanning across down with margin or group all three pictures and create another grid layout of of that container?
DJR
DJRā€¢17mo ago
Do you mean the gap in green is too small?
snxxwyy
snxxwyyā€¢17mo ago
yeah i'm sorry, must have forgot to specify that šŸ˜…, then when altering the gap property in the parent it affects the one where the red line is too as the container surrounding the large image is also a grid item.
DJR
DJRā€¢17mo ago
grid-gap will affect all of the gaps in the container. If that gap isn't large enough, you can apply a top margin to fix that.
snxxwyy
snxxwyyā€¢17mo ago
ah gotcha, thank you once again.
DJR
DJRā€¢17mo ago
All good. šŸ‘
snxxwyy
snxxwyyā€¢17mo ago
and i also have to adapt the "content" div in order to make it's items (the title and 2 paragraphs) the same width as the top three items? or is it supposed to auto span?
DJR
DJRā€¢17mo ago
If you're using grid-template-areas, you'll need to declare the span yourself.
snxxwyy
snxxwyyā€¢17mo ago
ah yeah i understand, i believe it's already spanning as its one row but the "sea scape" title seems to always be short of width however in the reference image it spans the whole way?
DJR
DJRā€¢17mo ago
Try adding justify-items: center to the element housing the title and the two paragraphs. justify-content: center may also work. I forget which to use lol.
snxxwyy
snxxwyyā€¢17mo ago
all good lol, i've tried both and it doesn't seem to be altering anything?
DJR
DJRā€¢17mo ago
The element will need to be of display: grid type. Since everything appears to be centered you could try applying it to the main container itself.
snxxwyy
snxxwyyā€¢17mo ago
i've tried it in both containers and it doesn't seem to be producing the same output as the reference image, the first two images are examples of what happens when i alter each container if that helps. and the second two images are what's desired and what mine looks like if that additionally helps.
DJR
DJRā€¢17mo ago
Do you have an updated CodePen to share?
snxxwyy
snxxwyyā€¢17mo ago
yeah for sure, it's all updated i have a feeling i've made a rookie mistake somewhere or it's to do with the way i've laid things out
DJR
DJRā€¢17mo ago
Ah I see why justify-content/justify-items: center; must be either justify-content: center; or justify-items: center; on your .container and .content classes. It turns out that justify-items is the one you want. Adding width: 100%; onto your .two-img class should fix the image size issues.
snxxwyy
snxxwyyā€¢17mo ago
that was completely a mistake on my half trying to show you it like that, i put the / to show that i tried both, i didn't put them on the same line like that šŸ˜…
DJR
DJRā€¢17mo ago
Oh I see, my bad. šŸ˜†
snxxwyy
snxxwyyā€¢17mo ago
nah all good, all me šŸ˜…
DJR
DJRā€¢17mo ago
You can play around with max-width on the .container class if you want to achieve your design exactly. Otherwise it looks very close to it. šŸ‘
snxxwyy
snxxwyyā€¢17mo ago
ah thank you, i can see how that'd work. thank you for the feedback šŸ˜„, and sorry for taking up a couple hours of your time for that.
DJR
DJRā€¢17mo ago
No problem, happy to help. šŸ˜„ I'm going to head off to bed now. Been awake for 21 hours so I'm surprised that I've been any help at all. šŸ¤£
snxxwyy
snxxwyyā€¢17mo ago
dang nearly hitting the all nighter over there šŸ˜…, have a good night šŸ‘
DJR
DJRā€¢17mo ago
Nearly šŸ˜‚ But my body can't do it like it used to lmao Goodnight!
snxxwyy
snxxwyyā€¢17mo ago
well that's something you can't argue with šŸ˜‚
Want results from more Discord servers?
Add your server