I am currently working on creating a CSS grid layout. The issue I'm facing is that the first element has a fixed height, causing the entire first row to have the same height. I want the elements in the second row to move up and fill the empty space in the first row. Is there a way to achieve this using CSS grid?https://i.sstatic.net/GRuv9.png
The webpage where I plan to implement this grid will have elements that vary in size based on user input.
I've experimented with grid-auto-columns, grid-auto-rows, and grid-auto-flow: dense; but so far, I haven't been able to achieve the desired outcome. Any suggestions would be greatly appreciated.
.container {
display: grid;
width: 800px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-gap: 1rem;
}
/* OTHER STYLES */
body {
background-color: #3b404e;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.item {
height: 100px;
background-color: #1EAAFC;
background-image: linear-gradient(130deg, #6C52D9 0%, #1EAAFC 85%, #3EDFD7 100%);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
color: #fff;
border-radius: 4px;
border: 6px solid #171717;
}
.item1 {
height: 250px;
}
<div class="container">
<div class="item item1"></div>
<div class="item item2"></div>
<div class="item item3"></div>
<div class="item item4"></div>
<div class="item item5"></div>
</div>
Check out my practice on Codepen: Codepen Link Here