-2

I'm currently trying to layout a fairly straightforward responsive image grid using CSS Grid (see image)

A static image of the CSS grid layout I'm attempting to create:

A static image of the CSS grid layout I'm attempting to create

The first row will show two images (both at 50% width), the second row will display three images (at aprox 33% each).

I have no problems with this layout using Flexbox but a CSS Grid solution eludes me. For the record, I'm still getting to grips with CSS Grid so perhaps the problem lies with me? Is this layout possible? Any hints/tips would be much appreciated.

Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
LucyR
  • 13
  • 5
  • 2
    Please [edit] the post and add a [mcve] of what you tried (Including relevant HTML+CSS) – Alon Eitan Apr 27 '19 at 15:47
  • use a 6-column grid - the first row grid items spanning 3 columns and the second row grid items spanning 2 columns apiece... you can see an example that uses grids (or flexboxes) [**`here`**](https://stackoverflow.com/questions/55868057/is-it-possible-to-control-item-count-in-a-row-by-flex/55871823#55871823) where it is 4 columns in first row and 3 in the second and so on, but similar logic... – kukkuz Apr 27 '19 at 16:25
  • Thank you, Alon. The links you supplied have been very helpful. – LucyR Apr 28 '19 at 13:13

1 Answers1

0

Here's an example. You can play with the units to fit your size requirements. Code here:

//HTML
<div class="gridcontainer">
    <div class="bigimage1"></div>
    <div class="bigimage2"></div>
    <div class="smallimage1"></div>
    <div class="smallimage2"></div>
    <div class="smallimage3"></div>
</div>

//CSS
.gridcontainer{
    background: #666;
    border: .65vw solid #666;
    display: grid;
    height: 81.75vh;
    width: 57.5vw;
    grid-gap: .7vw;
    grid-template-columns: 9vw 9vw 9vw 9vw 9vw 9vw;
    grid-template-rows: 48vh 32.5vh;
    grid-template-areas: 
    "bigimageleft bigimageleft bigimageleft bigimageright bigimageright bigimageright"
    "smallimageleft smallimageleft smallimagecenter smallimagecenter smallimageright smallimageright";
    }

.bigimage1{
    grid-area: bigimageleft;
    background: white;
    }
.bigimage2{
    grid-area: bigimageright;
    background: white;
    }
.smallimage1{
    grid-area: smallimageleft;
    background: white;
}
.smallimage2{
    grid-area: smallimagecenter;
    background: white;
}
.smallimage3{
    grid-area: smallimageright;
    background: white;
    }

Have a look at an example here: https://jsfiddle.net/L5gbfv7m/11/

Christopher Bennett
  • 803
  • 1
  • 8
  • 20
  • Thank you, Christopher. I really appreciate you taking the time to post a code solution for me. With some slight modifications to your code (to suit my project) I now have the solution I've been aiming for …but didn't quite manage! :) ~Lucy. – LucyR Apr 28 '19 at 13:16
  • No problem. Glad I could help. If you found the answer useful, would you mind marking the "accepted" checkbox next to it? It will help others find this solution in the future. – Christopher Bennett Apr 28 '19 at 13:25