【发布时间】:2013-04-03 18:50:10
【问题描述】:
我正在开发一个带有粘性页脚的网站。最近我在导航中添加了购物车预览功能。基本上在鼠标悬停时会打开一个 div 以显示购物车内的项目。其实没什么特别的。
当项目列表变得很长时,首先出现问题。包含项目的 div 以某种方式破坏了粘性页脚。
为了演示我创建了jsFiddle example 的行为。
我的 HTML 如下所示:
<div id = "main">
<div id = "navigation">
navigation
<div id = "cart">
cart
<div id = "cartItems">
<p>item 1</p>
<p>item 2</p>
<p>item 3</p>
<p>...</p>
</div>
</div>
</div>
<div id = "content">content</div>
<div id = "footer">footer</div>
</div>
CSS:
* {
margin:0;
padding:0;
}
html, body {
height: 100%;
}
#main {
width: 900px;
min-height: 100%;
margin: 0 auto;
position: relative;
background-color: lightpink;
}
#navigation {
height: 50px;
position: relative;
background-color: orange;
}
#content {
padding-bottom: 50px;
}
#footer {
width: 900px;
height: 50px;
position: absolute;
bottom: 0;
background-color: yellowgreen;
}
#cart {
width: 100px;
position: absolute;
top: 0;
right: 0;
background-color: red;
}
#cartItems {
display: none;
}
我希望有人可以给我一个提示。我真的被这个卡住了。
【问题讨论】:
-
+1 用小提琴提出格式正确的问题
-
中断页脚是什么意思?正如我认为您所说的,当列表很长时,列表会下降到页脚。因此,要解决此问题,您可以将 z-index 添加到#cart。 check this fiddle
-
看滚动条,页脚应该在页面底部,而不是窗口底部。
-
您为此使用任何服务器端语言吗?
标签: html css sticky-footer