I am trying to build a CSS grid
I do not want to have space between item2 and item3, and want these items to be aligned on top of the container.
Is this possible with CSS only, without modifying the HTML structure?
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
align-items: start;
}
.item1,
.item2,
.item3 {
border: 1px solid black;
}
.item1 {
grid-column: span 1;
grid-row: span 2;
}
.item1 img {
width: 80px;
height: 115px;
}
.item2,
.item3 {
grid-column: span 1;
grid-row: span 1;
}
<div class="grid-container">
<div class="item1">
<img src="https://dummyimage.com/80x115/000/fff">
</div>
<div class="item2">Element 2</div>
<div class="item3">Element 3</div>
</div>
3
Answers
Use the below code to fulfill your requirement.
Add these lines to your
.grid-container
style:Preview:
Here’s one way you could do it. Not the best but it works using CSS only, without changing the HTML structure.
HTML
CSS