I am facing a challenging problem with a relatively simple layout.
To summarize
- My layout is centered
- The sidebar background should extend all the way to the left
- The section background should extend all the way to the right
- The backgrounds are purely visual, the layout remains centered
- The sections have variable heights
- I attempted to use CSS grid to create a full-width layout, but it caused the center grouping to be lost
- I experimented with :before and :after with absolute positioning, but it failed when applying overflow-y scroll to the containers
- I prefer not to use JavaScript for the solution
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
.wrap {
width: 100%;
height: 100%;
background: #eee;
}
main {
margin: 0 auto;
width: 600px;
background: #ddd;
height: 100%;
display: flex;
}
aside {
background: #ccc;
height: 100%;
width: 100px;
overflow-y: auto;
}
.content {
flex: 1;
overflow-y: auto;
}
section {
display: block;
width: 100%;
}
section.blue {
background: blue;
}
section.yellow {
background: yellow;
}
section.green {
background: green;
}
<div class="wrap">
<main>
<aside>Aside</aside>
<div class="content">
<section class="blue">Blue</section>
<section class="yellow">Yellow</section>
<section class="green">Green</section>
</div>
</main>
</div>