当我添加新的 HTML 元素时,在 <body> 上重复 CSS 渐变背景
Repeated CSS gradient background on <body> as I add new HTML elements
我的 CSS 渐变背景有问题...当我只有 <body>
时,渐变背景看起来很完美,但现在我添加了新的 HTML 元素带有 CSS 代码,看起来像重复:
代码:
<!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;
}
主体的背景仅针对其内容高度(比视口短)设置。将 min-height: 100vh
添加到正文。
body {min-height: 100vh}
只需在bodyCSS
中添加min-height:100vh;
您的 Body CSS 将如下所示
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;
}
您需要添加:
body {
min-height: 100vh;
}
我的 CSS 渐变背景有问题...当我只有 <body>
时,渐变背景看起来很完美,但现在我添加了新的 HTML 元素带有 CSS 代码,看起来像重复:
代码:
<!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;
}
主体的背景仅针对其内容高度(比视口短)设置。将 min-height: 100vh
添加到正文。
body {min-height: 100vh}
只需在bodyCSS
中添加min-height:100vh;
您的 Body CSS 将如下所示
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;
}
您需要添加:
body {
min-height: 100vh;
}