行没有填满高度
Rows are not filling up the height
我一直在尝试使用 CSS 网格并尝试开发一个简单的网页。我正在使用 fr
单元均匀地创建显示我的内容并使其响应。均匀创建列以填满屏幕的 space。但另一方面,这些行没有填满 space。正在创建它们,但不会填满屏幕的整个高度。
这是我的 HTML:
<!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">
<link href="style.css" type="text/css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900" rel="stylesheet">
<title>Name of Site</title>
</head>
<body>
<div class="container">
<header class="header box">
<h1>Name</h1>
</header>
<nav class="info box">
<h2>General Information</h2>
</nav>
<div class="right box">
<h3>Right</h3>
</div>
<footer class="footer box">
<h2>Footer</h2>
</footer>
</div>
</body>
</html>
这是我的 CSS 代码:
/* Resets */
body {
margin: 0;
}
/* Typography */
h1, h2, h3 {
font-family: 'Roboto';
text-align: center;
font-variant-caps: all-petite-caps;
}
ul, li, p {
font-family: 'Roboto';
}
.box {
color: #ffffff;
padding: 10px 10px;
}
/* CSS Grid */
@media (min-width: 960px) {
.container {
display: grid;
grid-template-areas:
"h r"
"i r"
"f r";
grid-template-columns: 1fr 2fr;
grid-template-rows: 1fr 3fr 1fr;
}
}
.header {
grid-area: h;
background-color: #57B8BF;
}
.info {
grid-area: i;
background-color: #3A7B7F;
}
.footer {
grid-area: f;
background-color: #1D3D40;
color: #ffffff;
}
.right {
grid-area: r;
background-color: #ffffff;
color: black;
}
我不断得到的结果是这样的:
.
我有 Firefox 网格显示,因此您可以看到网格的布局方式。但是我用红色写的图像 space 现在在制作行时被包括在内。页脚不是应该在其列的末尾吗?
如何让行均匀分布页面的高度,就像对列所做的那样?
我有同样的问题,使用这个:
.container {
width: 100%;
height: 100vh;
}
只需将您的 container
和 html, body
调整为 100%
高度
html, body {
height: 100%;
}
.container {
height: 100%;
}
html, body {
height: 100%;
}
body {
margin: 0;
}
/* Typography */
h1, h2, h3 {
font-family: 'Roboto';
text-align: center;
font-variant-caps: all-petite-caps;
}
ul, li, p {
font-family: 'Roboto';
}
.box {
color: #ffffff;
padding: 10px 10px;
}
/* CSS Grid */
@media (min-width: 960px) {
.container {
height: 100%;
display: grid;
grid-template-areas:
"h r"
"i r"
"f r";
grid-template-columns: 1fr 2fr;
grid-template-rows: 1fr 3fr 1fr;
}
}
.header {
grid-area: h;
background-color: #57B8BF;
}
.info {
grid-area: i;
background-color: #3A7B7F;
}
.footer {
grid-area: f;
background-color: #1D3D40;
color: #ffffff;
}
.right {
grid-area: r;
background-color: #ffffff;
color: black;
}
<div class="container">
<header class="header box">
<h1>Name</h1>
</header>
<nav class="info box">
<h2>General Information</h2>
</nav>
<div class="right box">
<h3>Right</h3>
</div>
<footer class="footer box">
<h2>Footer</h2>
</footer>
</div>
我一直在尝试使用 CSS 网格并尝试开发一个简单的网页。我正在使用 fr
单元均匀地创建显示我的内容并使其响应。均匀创建列以填满屏幕的 space。但另一方面,这些行没有填满 space。正在创建它们,但不会填满屏幕的整个高度。
这是我的 HTML:
<!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">
<link href="style.css" type="text/css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900" rel="stylesheet">
<title>Name of Site</title>
</head>
<body>
<div class="container">
<header class="header box">
<h1>Name</h1>
</header>
<nav class="info box">
<h2>General Information</h2>
</nav>
<div class="right box">
<h3>Right</h3>
</div>
<footer class="footer box">
<h2>Footer</h2>
</footer>
</div>
</body>
</html>
这是我的 CSS 代码:
/* Resets */
body {
margin: 0;
}
/* Typography */
h1, h2, h3 {
font-family: 'Roboto';
text-align: center;
font-variant-caps: all-petite-caps;
}
ul, li, p {
font-family: 'Roboto';
}
.box {
color: #ffffff;
padding: 10px 10px;
}
/* CSS Grid */
@media (min-width: 960px) {
.container {
display: grid;
grid-template-areas:
"h r"
"i r"
"f r";
grid-template-columns: 1fr 2fr;
grid-template-rows: 1fr 3fr 1fr;
}
}
.header {
grid-area: h;
background-color: #57B8BF;
}
.info {
grid-area: i;
background-color: #3A7B7F;
}
.footer {
grid-area: f;
background-color: #1D3D40;
color: #ffffff;
}
.right {
grid-area: r;
background-color: #ffffff;
color: black;
}
我不断得到的结果是这样的:
我有 Firefox 网格显示,因此您可以看到网格的布局方式。但是我用红色写的图像 space 现在在制作行时被包括在内。页脚不是应该在其列的末尾吗?
如何让行均匀分布页面的高度,就像对列所做的那样?
我有同样的问题,使用这个:
.container {
width: 100%;
height: 100vh;
}
只需将您的 container
和 html, body
调整为 100%
高度
html, body {
height: 100%;
}
.container {
height: 100%;
}
html, body {
height: 100%;
}
body {
margin: 0;
}
/* Typography */
h1, h2, h3 {
font-family: 'Roboto';
text-align: center;
font-variant-caps: all-petite-caps;
}
ul, li, p {
font-family: 'Roboto';
}
.box {
color: #ffffff;
padding: 10px 10px;
}
/* CSS Grid */
@media (min-width: 960px) {
.container {
height: 100%;
display: grid;
grid-template-areas:
"h r"
"i r"
"f r";
grid-template-columns: 1fr 2fr;
grid-template-rows: 1fr 3fr 1fr;
}
}
.header {
grid-area: h;
background-color: #57B8BF;
}
.info {
grid-area: i;
background-color: #3A7B7F;
}
.footer {
grid-area: f;
background-color: #1D3D40;
color: #ffffff;
}
.right {
grid-area: r;
background-color: #ffffff;
color: black;
}
<div class="container">
<header class="header box">
<h1>Name</h1>
</header>
<nav class="info box">
<h2>General Information</h2>
</nav>
<div class="right box">
<h3>Right</h3>
</div>
<footer class="footer box">
<h2>Footer</h2>
</footer>
</div>