Flexbox with two columns. Each of them has centered content with a maximum width of X. The second column has overflow-y set to scroll.
Obviously, the scrollbar needs space and moves the centered contents of the second column to the left.
Is there a way to place content still exactly under another?
HTML:
<header>
<nav>nav</nav>
</header>
<main>
<section>section</section>
</main>
CSS
html, body {
margin: 0;
padding: 0;
height: 100vh;
}
body {
display: flex;
flex-direction: column;
}
header {
flex: 0 0 auto;
}
main {
flex: 1 1 auto;
overflow-y: scroll;
}
nav {
width: 800px;
margin: 0 auto;
}
section {
width: 800px;
margin: 0 auto;
}
See: https://codepen.io/anon/pen/VpXvyN
source
share