【发布时间】:2010-05-02 08:38:49
【问题描述】:
我有一个绝对定位的块元素和页面上的其他一些定位固定的元素。效果是顶部的块漂浮在页面上,效果很好。
下方元素中的链接不可点击。它们不应该是当 div 的内容超过它们时,而是当透明的“边缘”区域超过链接时它们是可见的,但点击只注册到覆盖 div。
仅当填充覆盖 div 时才会出现问题。但是,如果我只依赖边距,浏览器会忽略底部边距,因此滚动不会向上足够高。为了解决这个问题,我求助于底部的填充。这就是问题所在。
有没有干净的方法解决这个问题?我意识到我可以将下面的元素加倍并放在上面,但不透明度设置为 0。然而,这是一个不受欢迎的解决方案。
问题示例:
<!DOCTYPE html>
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<style>
#top, #bottom {
position: fixed;
border: 1 px solid #333;
background-color: #eee;
left: 100px;
padding: 8px;
}
#top {
top: 0;
z-index: 1;
}
#bottom {
bottom: 0;
z-index: 2;
}
#contentWrapper {
position: absolute;
margin: 100px 0 0 0;
/* Padding is used to make sure the scroll goes up further on the page */
padding: 0 0 100px 0;
width: 600px;
z-index: 3;
}
#content {
border: 1 px solid #333;
background-color: #eee;
height: 1000px;
}
</style>
</head>
<body>
<div id='top'><a href="#">Top link</a></div>
<div id='bottom'><a href="#">Bottom link</a></div>
<div id='contentWrapper'>
<div id='content'>Some content</div>
</div>
</body>
</html>
【问题讨论】:
标签: javascript html css