【发布时间】:2021-10-27 12:40:55
【问题描述】:
大家好,
我需要帮助,我想在我的<main> 中有 2 个部分,我希望第一部分填满整页,如果我滚动我让第二部分再次填满整页。所以我对此进行了测试:
html, body {
width: 100%;
height: 100%;
margin: 0;
}
.container {
display: grid;
grid-template-rows: auto 1fr auto;
grid-template-columns: 100%;
min-height: 100%;
}
header,
footer {
height: 100px;
background-color: rgba(0,0,0,0.7);
}
header {
}
main {
}
section {
display: block;
background: #CFF;
}
.one {
background: red;
height: 100%;
}
.two {
background: cyan;
height: 100%;
}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<div class="container">
<header></header>
<main>
<section class="one"></section>
<section class="two"></section>
</main>
<footer></footer>
</div>
</body>
</html>
如您所见,我的页脚位于第一部分的底部,但我希望他位于第二部分的真正底部。
如果可能的话,我想修复我的标题,但如果我把 position : fixed; 放在 header {} 我的标题是隐藏的??
抱歉我的英语不好。
你能帮帮我吗,祝你有美好的一天!
【问题讨论】:
-
html, body { height: 100%; }根本没有影响。height: 100%表示使用父级的全高。父母必须有一个定义的宽度而不是一个计算的宽度来适应内容。在任何情况下,html 和 body 都没有父级可以使用height: 100%;。你想要的是min-height: 100vh;
标签: html css css-grid responsive