How to place grid elements at the end of a container
P粉387108772
2023-08-28 13:48:05
<p>I have a grid container and I want my items to be at the bottom. </p>
<p>I have this actual</p>
<p>I want this
Expectations</p>
<p>
<pre class="brush:css;toolbar:false;">.container {
display: grid;
grid-template-columns: repeat(14, 1fr);
grid-template-rows: repeat(6, 1fr);
grid-gap: 8px;
width: 200px;
background: blue;
}
.item {
background-color: red;
color: white;
}
.item-1 {
grid-column: span 5;
grid-row: span 6;
}
.item-2 {
grid-column: span 4;
grid-row: span 5;
}
.item-3 {
grid-column: span 3;
grid-row: span 4;
}</pre>
<pre class="brush:html;toolbar:false;"><div class="container">
<div class="item item-1">item 1</div>
<div class="item item-2">item 2</div>
<div class="item item-3">item 3</div>
</div></pre>
</p>
<p>PS: I have tried place-items: end; and align-items: end;</p>
You can use the two values
grid-column
andgrid-row
start / end
syntax to determine the start and end position of the item.For example,
grid-row: 2 / span 3;
will start at the 2nd grid line, span 3 grid lines, and end at the 5th grid line.