Home > Enterprise >  Practicing CSS Grid and 100vh is not fully stretching
Practicing CSS Grid and 100vh is not fully stretching

Time:11-18

Below is a copy of my code. I checked some of the forums and saw that margin may be the issue, but I have it set to 0. I'm a bit stumped at this point. Any assistance is appreciated.

I was expecting for this to fully stretch across my page vertically and horizontally. It really is only about 1 column and does not stretch fully in either direction.

<!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>Grid Practice</title>
    <link rel="stylesheet" href="grid.css">
</head>
<body>
    <div >
        <header>Header</header>
        <main>Main</main>
        <nav>Navigation</nav>
        <aside>Sidebar</aside>
        <footer>Footer</footer>
    </div>
</body>
</html>



* {
    box-sizing: border-box;
    padding: 0;
    margin: o;
}

body {
    font-family: sans-serif;
    font-size: 16px;
    height: 100vh;
    display: grid;

    grid-template-areas:  
    "hd hd hd"
    "nav cont side"
    "nav foot foot";

}

header,
footer,
main,
aside,
nav {
    background-color: peachpuff;
    color: #fff;
    padding: 20px;
    border: palegoldenrod 1px solid;
}

header {
    grid-area: hd;
}

footer {
    grid-area: foot;
}

main {
    grid-area: cont;
}

aside {
    grid-area: side;
}

nav {
    grid-area: nav;
}

CodePudding user response:

I'm assuming you want the whole page in grid layout. In that case, the .container should have the grid property and not the body. Hope this helps!

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

body {
  font-family: sans-serif;
  font-size: 16px;
  height: 100vh;
}

.container {
  display: grid;
  grid-template-areas: "hd hd hd" "nav cont side" "nav foot foot";
}

header,
footer,
main,
aside,
nav {
  background-color: peachpuff;
  color: #fff;
  padding: 20px;
  border: palegoldenrod 1px solid;
}

header {
  grid-area: hd;
}

footer {
  grid-area: foot;
}

main {
  grid-area: cont;
}

aside {
  grid-area: side;
}

nav {
  grid-area: nav;
}
<body>
  <div >
    <header>Header</header>
    <main>Main</main>
    <nav>Navigation</nav>
    <aside>Sidebar</aside>
    <footer>Footer</footer>
  </div>
</body>

</html>

  • Related