I want to create a website with a background image and I have 3 requirements for it:
- Keeping the footer at the bottom of the page (easy)
- A background image that covers up 100% of the body height
- Some maximum page width, let's say 12800px
Sadly, I'm having issues with satisfying both 2. and 3. at the same time, but before I go more in depth about the problems, let me show the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/HELP-style.css">
</head>
<body>
<header><h1>HEADER</h1></header>
<main>
<!-- insert 1000 more lorem -->
<h3>Lorem ipsum</h3>
</main>
<footer><h1>FOOTER</h1></footer>
</body>
</html>
And the CSS:
html {
height: 100%; /* 1st req */
}
body {
min-height: 100%; /* 1st req */
display: flex;
flex-direction: column;
margin: 0 auto;
max-width: 1280px; /* 3rd req */
background-image: url("../images/myimg.jpg"); /* 2nd req */
background-size: cover;
background-position: center;
background-repeat: no-repeat;
border: 2px solid red;
}
main {
border: 2px solid blue;
}
footer {
margin-top: auto; /* 1st req */
border: 2px solid green;
}
As you can see, the background-size is set to cover, which almost works, until there's A LOT more content (or when you zoom in close enough), aka when you need a scrollbar to go up and down the page. When that happens the background image cuts-off after 100vh units. Even though it's set to cover.
What's even stranger, is that when I set background-size: 50px 100% Then that also doesn't work. Even though I explicitly state that I want the background image to take up 100% of the body, it only takes up 100vh, which confused me even more.
What's happening here? How can I actually achieve all 3 of my goals?