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.
Fr is a fractional unit and 1fr is for 1 part of the available space. The following are a few examples of the fr unit at work. The grid items in these examples are placed onto the grid with grid areas.
Auto-placement by column Using the property grid-auto-flow with a value of column . In this case grid will add items in rows that you have defined using grid-template-rows . When it fills up a column it will move onto the next explicit column, or create a new column track in the implicit grid.
You can specify the width of a column by using a keyword (like auto ) or a length (like 10px ). The number of columns is determined by the number of values defined in the space-separated list.
An HTML element becomes a grid container when its display property is set to grid or inline-grid .
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With