18

Is it possible do set a div's height and width in amount of rows/columns they should span, without specifying exactly which columns or rows they should go into?

For example, if I have two classes, say .long and .wide, and I want the .long class to be 3 rows high, and 1 column wide, and the .wide class be 3 columns wide but only 1 row high.

My specific use case involves Angular 5, I'm dynamically loading in objects and would like to make some of them larger than others. I know I could do this using flexboxes and setting the height, but was curious to see if I could achieve the same (much neater) with a grid, but all I've been finding has every class specified with grid-column: x/y; grid-row: a/b and the like.

1

1 Answer 1

30

There is an alternative syntax for grid-row and grid-column that sets a span:

.grid {
    display: grid;
    border: solid 1px black;
    grid-auto-rows: 30px;
    grid-auto-columns: repeat (5, 50px);
    grid-gap: 5px;
}

.grid div {
    background-color: lightgreen;
}

.wide {
    grid-column: span 3;
}

.long {
    grid-row: span 3;
}
<div class="grid">
<div></div>
<div class="long">LONG</div>
<div class="wide">WIDE</div>
</div>

1
  • I think that's exactly what I was looking for, thank you so much!
    – Siebe
    Apr 20, 2018 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.