<footer> only occupies the first 3 columns created in the CSS Grid. How do I occupy the 4 screen columns?

Asked

Viewed 51 times

0

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: white;
}

div.container {
  display: grid;
  grid-template-columns: 3fr 1fr;
  grid-template-rows: 20vh 70vh 10vh;
  grid-template-areas: "h h" "m a" "f f";
}

header {
  background: yellow;
  grid-area: h;
}

main {
  background: blue;
  grid-area: m;
}

aside {
  background: green;
  grid-area: a;
}

footer {
  background: red;
  grid: f;
}
<!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>Site</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="container">
    <header></header>
    <main></main>
    <aside></aside>
    <footer></footer>
  </div>
</body>

</html>

I’m learning CSS-Grid and can’t figure out why the footer doesn’t occupy the 4 columns created, just the first 3. Can anyone help me, Prf?

1 answer

3


footer has the attribute grid instead of grid-area, this is the problem!

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: white;
}

div.container {
  display: grid;
  grid-template-columns: 3fr 1fr;
  grid-template-rows: 20vh 70vh 10vh;
  grid-template-areas: "h h" "m a" "f f";
}

header {
  background: yellow;
  grid-area: h;
}

main {
  background: blue;
  grid-area: m;
}

aside {
  background: green;
  grid-area: a;
}

footer {
  background: red;
  grid-area: f;
}
<!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>Site</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="container">
    <header></header>
    <main></main>
    <aside></aside>
    <footer></footer>
  </div>
</body>

</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.