3 回答

TA贡献1946条经验 获得超3个赞
页脚是否需要进行硬编码width?这似乎是您遇到最多问题的地方。如果您仅在页脚中有需要显示的内容,并且内容可能比页眉宽,那么我建议您使用如下解决方案:
html, body, main {
width: 100%;
height: 100%;
background: #888;
margin: 0;
padding: 0;
}
header {
width: 100%;
height: 20%;
background: rgba(0,255,0,.1);
}
footer {
display: flex;
overflow-x: scroll;
height: 80%;
background: rgba(255,0,0,.1);
}
h1 {
margin-left: 70px;
}
<main>
<header>Header</header>
<footer>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
<h1>Content</h1>
</footer>
</main>

TA贡献1851条经验 获得超5个赞
将标头CSS更改为此
header {
width: 100%;
height: 20%;
background: rgba(0,255,0,.1);
position: fixed;
float-left: auto;
float-right: auto;
}
Fixed元素相对于html文档而不是父容器,并且不受滚动影响。Float left and right auto将其居中放置在页面上。
如果要在垂直滚动footer上方进行浏览header,则应使用z-index属性。
footer {
width: 10000px;
height: 80%;
background: rgba(255,0,0,.1);
position: fixed;
z-index: 1
}
你也可以在绝对fixed和absolute相对于父容器之间进行比较fixed
添加回答
举报