Currently, I am delving into the realm of CSS grid to better comprehend its functionality. In my layout design, there are two menus (colored in red) positioned on either side of a central main content box (colored in blue).
As the screen size reduces and accommodation for three columns becomes unfeasible, my objective is to have the second menu (on the right side) shift directly below the first one (on the left side).
https://i.sstatic.net/5hYKH.png
The height variations among the main content and side menus are arbitrary, as their heights depend on the quantity of content or menu items they contain. The solution should remain effective regardless of these height discrepancies.
The current layout is almost flawless, with the minor issue being that the second menu appears below the conclusion of the main content rather than directly following the first menu. How can this be rectified?
.main-container {
width: 100%;
height: 100%;
}
@media only screen and (min-width: 400px) {
.main-container {
display: grid;
grid-gap: 20px;
grid-template-columns: 40px 80px 40px;
justify-content: center;
}
}
@media only screen and (max-width: 400px) {
.main-container {
display: grid;
grid-gap: 20px;
grid-template-columns: 40px 80px;
justify-content: center;
}
}
.side-menu {
width: 100%;
height: 50px;
background-color: red;
}
.main-content {
width: 100%;
height: 300px;
background-color: blue;
}
<div class="main-container">
<div class="side-menu"></div>
<div class="main-content"></div>
<div class="side-menu"></div>
</div>
In adherence to the title's instruction "CSS grid layout," I am aiming to achieve this without resorting to JavaScript.