I'm trying to understand the CSS grid. My layout consist of two menus (red), one on each side of a main content box in the middle (blue).
When the screen becomes smaller and there is not enough space for 3 columns, I want the second (right) side menu to appear right under the first (left) one.
Consider the height of main content and the side menus as random values, as the height will change depending on how much content/menu items is in them. Solution should work regardless of height.
My current layout almost works, except that the second menu appears under the end of the main content, and not right after the first menu. How can I solve this?
.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>
Like the title states "CSS grid layout" i don't want to use js.



