Making the header { position:fixed } in a basic
<header></header>
<article></article>
<footer></footer>
layout, causes some quirks, since the article now starts at top = 0 such that its content is hidden by the header. A common workaround is to set the article's padding or margin equals to the header height. And here lays the problem: Assuming some header size is risky. Javascript can be used to measure the header heigth and set the padding accordingly, but this is not pure css. Duplicating the header with { visibility: hidden, position: initial } is the best pure CSS solution I found:
http://codepen.io/parkerbennett/pen/lzqEH
or here at position fixed header in html (@James in a comment)
Question: In the year 2017, is there a pure CSS (no JS) solution without duplicating the header, that avoids this workaround?
I came up with this flex solution, but it is not perfect and therefore does not beat the workaround above (which from user perspective is perfect):
<html>
<head>
<title>lab</title>
<style>
/* reset */
body, div {
padding: 0;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}
article {
display: flex;
flex: 1;
overflow: auto;
}
</style>
</head>
<body>
<header>header text</header>
<article>
scrollable text
</article>
<footer>footer content</footer>
</body>
</html>
The problem here is, the scrollbar does not go over the full browser window height, but only along the article height.
I also thought about using CSS3 calc() but we cannot measure the height of the header and use this as margin inside the article-css.