【发布时间】:2019-06-14 15:29:15
【问题描述】:
现在我创建了一个或多或少只有固定和绝对内容的页面。第一个视口很容易创建,因为它的最大高度为 100vh。所以我用 margin-top: 100vh 设置了第二部分的样式。现在一切正常。但第二部分不再是 100vh 高度。高度或多或少是未知的。
现在我想创建一个新的部分或页脚。但问题是它卡在页面顶部。就像没有其他内容一样。我认为这是因为 position: absolute 在所有其他元素上。 位置:绝对和底部:0 也不适用于页脚。然后它只是粘在视口的底部而不是整个页面的底部。
如何设置下一个内容的样式以使其低于其他内容?
我使用 position: absolute 的原因是为了一个固定的背景,用 css 创建的。 也许有一种更聪明的方法可以让内容与背景重叠而没有绝对位置?
我认为这是您解决我的问题所需的相关代码:
body {
padding: 0;
margin: 0;}
.first {
position: absolute;
color: white;
height: 100vh;
width: 100vw;
}
.second {
position: absolute;
margin-top: 110vh;
color: white;
width: 100vw;
}
footer {
position: absolute;
background-color: coral;
z-index: 200;
height: 10em;
width: 100vw;
}
.background {
background: radial-gradient(black 15%, transparent 16%) 0 0, radial-gradient(rgba(255, 255, 255, .1) 15%, transparent 20%) 0 1px;
background-color: #12364a;
background-size: 12px 12px;
width: 100vw;
height: 100vh;
min-height: 300px;
position: fixed;
overflow: hidden;
background-attachment: fixed;
z-index: -1;
}
.background:after {
content: '';
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background-image: radial-gradient(circle, transparent 0%, rgba(7, 9, 11, 0.56) 100%);
}
<div class="first">
Lorem ipsum first page
</div>
<div class="second">
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
<p>Some Images here</p>
</div>
<footer>
this is the footer
</footer>
<div class="background"></div>
【问题讨论】:
-
请将相关代码 sn-ps 发布到您的问题中。
-
发布您的代码。
标签: html css footer positioning absolute