gpt4 book ai didi

html - 底部的页脚与 css 网格?想不通?

转载 作者:行者123 更新时间:2023-12-05 01:41:12 26 4
gpt4 key购买 nike

我看过其他教程,了解如何在内容很少时使用 css 网格使页脚粘在底部。但我想不通。

如果你能帮忙,那就太好了。我正在学习 css 网格,我断断续续地花了几天时间试图弄明白。

* {
margin: 0;
padding: 0;
color: #ffffff;
font-family: helvetica;
}

body {
background-color: #191919;
}

html body {
height: 100%;
width: 100%;
}

.grid {
min-height: 100%;
display: grid;
grid-template-columns: 10% 40% 40% 10%;
grid-template-rows: 50px 1fr auto;
grid-row-gap: 10px;
grid-template-areas:
"header header header header"
". main main ."
"footer footer footer footer";
}
/*Header*/

.header {
grid-area: header;
background-color: red;
display: grid;
position: fixed;
width: 100%;
grid-template-columns: 40% 60%;
grid-template-areas:
"title navigation"
}

.title {
grid-area: title;
text-align: center;
}

.navigation {
grid-area: navigation;
}

.title .navigation {
}

/*Main*/

.main {
margin-top: 50px;
grid-area: main;
background-color: #323232;
border-radius: 10px;
}

/*Footer*/

.footer {
grid-area: footer;
background-color: black;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Mortrix</title>
</head>
<body>

<div class="grid">

<!-- Header -->

<div class="header">

<div class="title"> <h1>Mortrix</h1></div>

<div class="navigation">Navigation</div>

</div>

<!-- Main -->

<div class="main">

This is some content

</div>

<!-- Footer -->

<div class="footer">Footer

</div>

</div>

</body>
</html>

我知道这个问题已经被问过了,但我正在寻找一个针对我自己的代码的修复程序。对不起,如果我错过了一些明显的东西。

最佳答案

您只需使用 Viewport Height (vh) 即可将页脚固定在窗口底部。该单位基于视口(viewport)的高度。值 1vh 等于视口(viewport)高度的 1%。所以在这里我只是设置了 .gridmin-height: 100vh 而不是 min-height: 100%

      * {
margin: 0;
padding: 0;
color: #ffffff;
font-family: helvetica;
}

body {
background-color: #191919;
}

html body {
height: 100%;
width: 100%;
}

.grid {
min-height: 100vh;
display: grid;
grid-template-columns: 10% 40% 40% 10%;
grid-template-rows: 50px 1fr auto;
grid-row-gap: 10px;
grid-template-areas:
"header header header header"
". main main ."
"footer footer footer footer";
}
/*Header*/

.header {
grid-area: header;
background-color: red;
display: grid;
position: fixed;
width: 100%;
grid-template-columns: 40% 60%;
grid-template-areas:
"title navigation"
}

.title {
grid-area: title;
text-align: center;
}

.navigation {
grid-area: navigation;
}

.title .navigation {
}

/*Main*/

.main {
margin-top: 50px;
grid-area: main;
background-color: #323232;
border-radius: 10px;
}

/*Footer*/

.footer {
grid-area: footer;
background-color: black;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Mortrix</title>
</head>
<body>

<div class="grid">

<!-- Header -->

<div class="header">

<div class="title"> <h1>Mortrix</h1></div>

<div class="navigation">Navigation</div>

</div>

<!-- Main -->

<div class="main">

This is some content

</div>

<!-- Footer -->

<div class="footer">Footer

</div>

</div>

</body>
</html>

关于html - 底部的页脚与 css 网格?想不通?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55012845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com