When I inspect the codes below, I noticed the body tag can’t stretch full height according to HTML height due to that the scroll appears, and I don’t want that.
I try set display to flex column and that work perfect, no scroll and that size as my expected. But I can’t understand why it’s work when I set display to flex column.
* {
padding: 0;
margin: 0;
}
body {
width: 100%;
height: 100vh;
background-color: white;
}
main {
width: 100%;
height: 100vh;
> .header {
height: 15%;
background: gray;
margin: 1rem;
}
> .body {
height: 70%;
margin: 1rem;
display: flex;
> aside {
width: 30%;
height: 100%;
background: gold;
}
> article {
width: 70%;
height: 100%;
background: gray;
margin-left: 1rem;
}
}
> .footer {
height: 15%;
background: gray;
margin: 1rem;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<title>Float Property</title>
</head>
<body>
<main>
<section class="header"></section>
<section class="body">
<aside></aside>
<article></article>
</section>
<section class="footer"></section>
</main>
</body>
</html>
2
Answers
If you visually inspect your sections you have four distinct margins being produced.
Each of these areas uses 1rem or 16px. So you can use
calc()
on the body height to accommodate these areas to remove the overflow that is adding scroll bar.I also changed the height of main to 100%.
This is a layout that begs for CSS-Grid, substituting
gap
for the problematicalmargin
s.