【发布时间】:2016-08-15 23:43:12
【问题描述】:
情况:
给出以下简化的 HTML 示例:
- 将页脚放在内容的后面,使其底部粘性
- 滚动到页面末尾时:页脚应从内容后面展开
我能够做到这一点,但是当我将 html 和 body 都设置为 overflow-x 属性为 hidden 时,页脚中的这些链接不可点击。
情况更新:
我知道可以将 #content 的 z-indices 设置为 2 并将 footer 的 z-indices 设置为 1 以使链接可点击,但这会干扰来自页面不同部分的 multizoom.js 并且不会我感兴趣的。
问题:
将overflow-x 设置为html 和body 与页脚中的链接有何关系?为什么必须 both 元素设置这个属性? (如果其中一个省略了overflow-x,则链接可点击)
事实上,对我来说,不在原始项目中设置overflow-x 已经没有问题了,因为它是过时样式尝试的遗留物,并且已经被删除。但我很好奇为什么会有这么奇怪的行为?
示例:
/* This statement prevents the links in the footer
* from being clickable */
html, body {
overflow-x: hidden;
}
/* necessary statements to put footer behind content and
* make it bottom sticky behind content */
#content {
/* opaque bg color to block out footer*/
background: lightgrey;
/* border bottom to see where content ends */
border-bottom: 1px solid black;
/* arbitrary height as content placeholder to provoke scrolling */
height: 1500px;
/* use margin to stretch the page in order for
* footer to become visible at the end of scrolling */
margin-bottom: 120px;
}
footer {
/* bg color to distinguish footer from content */
background: grey;
/* make footer 120px high, centered */
padding: 50px;
line-height: 20px;
text-align: center;
/* put footer one layer behind content so that content scrolls
* before footer while footer itself is fixed at the bottom */
z-index: -1;
position: fixed;
bottom: 0;
/* use all the width possible */
width: 100%;
}
body {
/* make page use the whole panel */
margin: 0;
}
<html>
<body>
<div id="content">
Here is the content, scroll down until end of page
</div>
<footer>
<a href="#">Here is the footer link (not clickable at the moment)</a>
</footer>
</body>
</html>
【问题讨论】:
-
当您将
#content相对设置为z-index: 2;和页脚z-index: 1;时,一切正常。似乎 body 对z-index: -1;有问题。 -
我知道它适用于 z-indexs 2 vs 1(我将更新问题),但这会干扰多缩放脚本(这将是一个完全不同的问题)
-
@xmoex 所以
#content不应该有z-index?还是应该有z-index: -1;的footer? -
@Green
#content不应该有 z-index。顺便说一句:这不是以不同的方式解决问题,我很感兴趣为什么问题会按原样解决(或者溢出-x 扮演了什么角色)
标签: html css z-index footer sticky-footer