1

I have a problem with my CSS gradient background... When I only had the <body>, the gradient background looked perfect on it, but now that I have added new HTML elements with CSS code, it looks like repeated:

enter image description here

Code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Topiks Quizz</title>
  </head>
  <body>
    <header>
      <h1>Topiks Quizz</h1>
      <nav>
        <ul>
          <li>Inicio</li>
        </ul>
        <ul>
          <li>Categorías</li>
        </ul>
      </nav>
    </header>

    <section id="container">
      <article>
        <div class="card">
          <img src="./assets/img_avatar.png" alt="Avatar" style="width:100%">
          <div class="container">
            <h4><b>John Doe</b></h4> 
            <p>Architect & Engineer</p> 
          </div>
        </div>
      </article>
    </section>
  </body>
</html>
@font-face {
    font-family: NotoSans;
    src: url(./assets/fonts/NotoSans-Regular.ttf);
}

* {
    font-family: NotoSans;
    margin: 0;
    padding: 0;
}

body {
    background: rgb(174,238,187);
    background: linear-gradient(22deg, rgba(174,238,187,1) 0%, rgba(162,222,236,1) 47%, rgba(148,233,212,1) 100%);
}

header {
    background-color: rgba(255, 255, 255, 30%);
    width: 100%;
    height: 50px;
}

header h1 {
    float: left;
}

header nav ul {
    list-style: none;
    float: right;
    padding: 10px;
}

.card {
    margin: 30px 30px;
    background-color: white;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
    transition: 0.3s;
    width: 200px;
  }
  
.card:hover {
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
} 
  
.container {
    padding: 2px 16px;
}
pavel
  • 26,538
  • 10
  • 45
  • 61

3 Answers3

1

Background for body is set just for its content height (shorter than viewport). Add min-height: 100vh to body.

body {min-height: 100vh}
pavel
  • 26,538
  • 10
  • 45
  • 61
1

Just add min-height: 100vh; in body CSS
Your Body CSS will look like Below

body {
    background: rgb(174,238,187);
    background: linear-gradient(22deg, rgba(174,238,187,1) 0%, rgba(162,222,236,1) 47%, rgba(148,233,212,1) 100%);
    min-height: 100vh;
}
0

you need to add :

    body {
       min-height: 100vh; 
}
Yassine
  • 1
  • 1