I have a grid layout with two columns. Each sections is full width (two columns one row). The number of sections/rows is dynamic. In addition, I would like the menu DIV to occupy the first column of each row (overlapping the sections). In theory, the code should look like the following. Each section starts in the first column and ends in the last column. The menu, on the other hand, occupies the first column and extends to the last row. In practice, this doesn’t work. If I set the exact coordinates for each item using grid-area then it starts to work, but I can’t do it because I don’t know the number of sections/rows. Any ideas?
HTML:
<div class="scrollSections__grid">
<div class="scrollSections__section"></div>
<div class="scrollSections__section"></div>
<div class="scrollSections__section"></div>
<div class="scrollSections__section"></div>
<div class="scrollSections__section"></div>
<div class="scrollSections__section"></div>
... (nth-elements)
<div class="scrollSections__menu"> </div>
</div>
CSS
.scrollSections__grid {
display: grid;
grid-template-columns: 1fr 3fr;
}
.scrollSections__section {
min-height: 100svh;
border: 2px solid blue;
grid-row: 1 / -1;
padding: 50px;
background: red;
}
.scrollSections__menu {
border: 2px solid red;
grid-area: 1 / 1 / -1 / 2;
padding: 30px;
}
2
Answers
If you’re looking for a grid, where the Menu occupies the the first column, and all other columns occupy the second column, you can continue using your grid method and simply add an encapsulating flex container.
You need to set the menu with position absolute, see the snippet