In order to make my header fit with all the viewports, I'm using the classic CSS rule height: 100vh;
and it works like a charm… except on my mobile.
Actually, on the bottom of the screen the header is taller than the viewport (20px or 30px more than it should do). Because of this issue, some of the content at the bottom of the header is the hidden on mobile devices.
I've tried to fix the bug with the Chrome DevTools Console, but everything is fine when I'm using the mobile view (with all the devices).
It seems the issue comes from the browser's address bar on my mobile (I'm using Chrome).
What am I missing ? How to fix it properly ?
Here you have the html :
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Test</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>Lorem ipsum</header>
<main>
<p>Lorem ipsum</p>
</main>
</body>
</html>
And here the CSS :
@charset "UTF-8";
/** RESET CSS **/
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, main{display:block;}
*{margin:0;padding:0;border:0;list-style:none;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}
header{
height: 100vh;
background: green;
font-size: 22px;
}
html, body { margin: 0; }
– Paunchy* { margin: 0; }
). – Alfieri*
is less then a normal tag such as<body>
so if a browser defaults to a certain margin, the*
will not reset this. If you set the header to 100vh then the main section will sit below the header. – Paunchyhtml, body, body > header { height: 100%; margin: 0; }
because 100vh is a calculated absolute value and 100% looks at the space that is available. – Paunchy