In my CSS Grid layout, I have a 3 x 3 grid setup.
Within a row, I have three items labeled A, B, and C.
I am trying to make item C span two rows using grid-row: 1 / span 2, but it's not appearing in the correct column. It's showing up in the first column instead of the third where it should be.
I want to keep item C in its original place within the HTML structure.
One solution is to explicitly set grid-column: 3 / span 1, but I prefer not to do this. I want the items to be displayed as they are in the HTML.
Is there a way to prevent this unexpected behavior?
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
}
h1 {
border: 2px solid;
padding: 0;
margin: 0;
font-size: 20px;
}
.a {
grid-row: 1 / span 2;
background: orange;
}
<div class="grid-container">
<div>
<h1>A</h1>
</div>
<div>
<h1>B</h1>
</div>
<div class="a">
<h1>C</h1>
</div>
</div>