Search code examples
htmlcsssassmargin

Why isn't the body stretching to full view port height?


I am making a portfolio site and now working on the projects section. I am using the grid display for the main div wrapper. At the beginning of my CSS, I set the margin of the .main, body, and html to 0 so that I don't have any leftover space on one of the sides. For some reason, there's a weird gap at the bottom of the page: gap I have tried setting the margin of a few more elements to 0, but nothing seems to work. Do you have an idea about what may be causing this?

@import url("https://fonts.googleapis.com/css?family=Roboto&display=swap");
html,
body,
.main {
  margin: 0;
  height: 100%;
  width: 100%;
}

body {
  background-image: radial-gradient(#181818, #050505);
}

body .nav {
  margin: 10px 0;
  text-align: center;
  font-family: 'Roboto', sans-serif;
  font-size: 2vw;
}

body .nav a,
body .nav a:visited {
  border-radius: 5px;
  padding: 0.2vh 0.65vw;
  margin: auto 30px;
  color: whitesmoke;
  text-decoration: none;
  -webkit-transition: 0.275s;
  transition: 0.275s;
}

body .nav a:hover {
  color: #f2f2f2;
  background-color: rgba(163, 163, 163, 0.1);
}

body .main {
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: 2.5% 30% 2.5% 30% 2.5% 30% 2.5%;
      grid-template-columns: 2.5% 30% 2.5% 30% 2.5% 30% 2.5%;
  -ms-grid-rows: 2.5% 40% 2.5% 40% 2.5%;
      grid-template-rows: 2.5% 40% 2.5% 40% 2.5%;
}

body .main img {
  border-radius: 3%;
  height: 100%;
}

body .main #img1 {
  -ms-grid-column: 2;
  -ms-grid-column-span: 1;
  grid-column: 2/3;
  -ms-grid-row: 2;
  -ms-grid-row-span: 1;
  grid-row: 2/3;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Projects</title>
    <link rel="stylesheet" href="../../styles/styles-projects.css" />
  </head>
  <body>
    <div class="nav">
      <a href="../portfolio/portfolio.html">PORTFOLIO</a>
      <a href="../../../index.html">HOME</a>
    </div>
    <div class="main">
      <img id="img1" src="../../images/Project-1.PNG" alt="Project card" />
    </div>
  </body>
</html>

Gist code: https://gist.github.com/VlatkoStojkoski/d8f9f300fbd57f5987c6bb66fb9206bf


Solution

  • you have set your grid-template-rows to only equal 87.5% of the height.

    If you adjust these values to equal 100% if will fill the full height correctly

    i.e.

    grid-template-rows: 2.5% 45% 5% 45% 2.5%