I am currently working on a two-column layout. The left column (header) is set to be sticky/fixed, while the right column remains static. In my HTML structure, I have 3 sibling elements (header
, div.content-column
, footer
). The footer is positioned below the .content-column
.
I am seeking a solution that does not involve nesting .content-column
with footer
, and avoids using margin-left
to position the footer next to the header. Any suggestions?
Thank you in advance!
body, ul {margin:0;}
header {
background-color: lightgreen;
}
.content-column {
background-color: lightblue;
font-size:3rem;
}
footer {
background-color: lightgray;
}
@media (min-width: 600px) {
body {
display: flex;
flex-wrap: wrap;
flex-direction: row;
min-height: 100vh;
}
header {
position: -webkit-sticky;
position: sticky;
top: 0;
overflow-y: auto;
display: flex;
flex: 0 1 40vw;
flex-direction: column;
align-self: flex-start;
height: 100vh;
max-width: 40vw;
}
.content-column {
display: flex;
flex-direction: column;
flex: 0 1 60vw;
background-color: lightblue;
}
footer {
margin-left: 40vw;
}
}
<header>
<a href="#">logo</a>
<span>logo subtitle</span>
<nav>
<ul>
<li>about</li>
<li>contact</li>
</ul>
</nav>
</header>
<div class="content-column">
<main>
<article>
Quo consequatur dolores facilis fugiat. Maxime non quam eos nisi voluptatem autem minus autem. Consectetur aut molestiae asperiores at impedit. Quam doloribus ut et impedit hic veritatis quia. Quo consequatur dolores facilis fugiat. Maxime non quam eos nisi voluptatem autem minus autem. Consectetur aut molestiae asperiores at impedit. Quam doloribus ut et impedit hic veritatis quia.
Quo consequatur dolores facilis fugiat. Maxime non quam eos nisi voluptatem autem minus autem. Consectetur aut molestiae asperiores at impedit. Quam doloribus ut et impedit hic veritatis quia.…
Quo consequatur dolores facilis fugiat. Maxime non quam eos nisi voluptatem autem minus autem. Consectetur aut molestiae asperiores at impedit. Quam doloribus ut et impedit hic veritatis quia.…
</article>
</main>
</div>
<footer>
2023
</footer>