抱歉,我对此很陌生,所以我可能是个白痴。
我正在为新创业公司建立网站,但遇到了一个问题,当使用下面的代码时,它可以很好地实现我的网站,但是这完全阻止了我向下滚动网站,据我所知,它甚至可能阻止其余页面的加载。它对每个页面都执行此操作,所有加载都在每个页面的顶部,但我似乎什么也去不了,侧面的滚动条也消失了,表明没有更多内容了。如果我删除CSS,一切都会恢复正常。
如下所示的代码(仅在它稍大一些时才起作用,但这对我来说很合适):</ p>
body {
width: 100%;
height: 100%;
position: fixed;
background-color: #34495e;
}
.content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
height: 160px;
overflow: hidden;
font-family: 'Lato', sans-serif;
font-size: 35px;
line-height: 40px;
color: #ecf0f1;
}
.content__container {
font-weight: 600;
overflow: hidden;
height: 40px;
padding: 0 40px;
}
.content__container:before {
content: '[';
left: 0;
}
.content__container:after {
content: ']';
position: absolute;
right: 0;
}
.content__container:after, .content__container:before {
position: absolute;
top: 0;
color: #16a085;
font-size: 42px;
line-height: 40px;
-webkit-animation-name: opacity;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
animation-name: opacity;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.content__container__text {
display: inline;
float: left;
margin: 0;
}
.content__container__list {
margin-top: 0;
padding-left: 125px;
text-align: left;
list-style: none;
-webkit-animation-name: change;
-webkit-animation-duration: 10s;
-webkit-animation-iteration-count: infinite;
animation-name: change;
animation-duration: 10s;
animation-iteration-count: infinite;
}
.content__container__list__item {
line-height: 40px;
margin: 0;
}
@-webkit-keyframes opacity {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
@-webkit-keyframes change {
0%, 12.66%, 100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
16.66%, 29.32% {
-webkit-transform: translate3d(0, -25%, 0);
transform: translate3d(0, -25%, 0);
}
33.32%,45.98% {
-webkit-transform: translate3d(0, -50%, 0);
transform: translate3d(0, -50%, 0);
}
49.98%,62.64% {
-webkit-transform: translate3d(0, -75%, 0);
transform: translate3d(0, -75%, 0);
}
66.64%,79.3% {
-webkit-transform: translate3d(0, -50%, 0);
transform: translate3d(0, -50%, 0);
}
83.3%,95.96% {
-webkit-transform: translate3d(0, -25%, 0);
transform: translate3d(0, -25%, 0);
}
}
@keyframes opacity {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
@keyframes change {
0%, 12.66%, 100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
16.66%, 29.32% {
-webkit-transform: translate3d(0, -25%, 0);
transform: translate3d(0, -25%, 0);
}
33.32%,45.98% {
-webkit-transform: translate3d(0, -50%, 0);
transform: translate3d(0, -50%, 0);
}
49.98%,62.64% {
-webkit-transform: translate3d(0, -75%, 0);
transform: translate3d(0, -75%, 0);
}
66.64%,79.3% {
-webkit-transform: translate3d(0, -50%, 0);
transform: translate3d(0, -50%, 0);
}
83.3%,95.96% {
-webkit-transform: translate3d(0, -25%, 0);
transform: translate3d(0, -25%, 0);
}
}
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<div class="content">
<div class="content__container">
<p class="content__container__text">
We Are
</p>
<ul class="content__container__list">
<li class="content__container__list__item">Freight Documents</li>
<li class="content__container__list__item">Professional</li>
<li class="content__container__list__item">Experienced</li>
<li class="content__container__list__item">Reliable</li>
</ul>
</div>
</div>
答案 0 :(得分:4)
您已将position: fixed
应用于body
,这将阻止页面滚动。
答案 1 :(得分:0)
这是因为您已将position:fixed
赋予您的body元素。
最好的做法是将代码包装在div中,然后在将其传递给主体时为其赋予position: fixed
这种样式。
但是随后,您必须将其他元素包装在主div中,并为其赋予margin-top
等于此代码div的高度。
理想的情况是不要使用固定的位置(如果您不希望它在滚动时停留在顶部),而只是给该div设置一个固定的高度。
希望对您有帮助。
答案 2 :(得分:0)
从主体中移除position: fixed;
,它将主体保持在固定位置。并在下面添加一些内容,即可滚动。