2013-04-03 45 views
2

我正在一个站点与粘脚。最近,我为导航添加了购物车预览功能。基本上mouseover打开一个div来显示购物车内的物品。其实没什么特别的高div打破粘脚footer

问题首先发生在项目列表变得很长时。包含项目的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; 
} 

我希望有人可以给我一个提示。我真的被困在这一个。

+0

+1对于格式良好的问题 –

+0

打破页脚意味着什么?正如我认为,当列表很长时,你会说列表会列入页脚。所以要解决这个问题,你可以将z-index添加到#cart。 [检查这个小提琴](http://jsfiddle.net/PMabQ/19/) – crazyrohila

+0

看看滚动条,页脚应该在页面的底部,而不是窗口的底部。 –

回答

0

您在这里有几个选项。选择是由你

  1. 较高Z-index添加到选项面板,使其显示页脚的顶部(不好因为如果项目列表太长,那么它会往下走超越页脚并在页脚后显示一些空白区域)。

  2. 添加overflow:scrollmain DIV,并允许项目列表下沉到内容(不好,如果是沉则用户无法看到的内容)。

  3. 指定最大高度为项列表和使overflow:scrool(退出确定,但用户需要沿着一路下跌双击自动滚屏)

  4. 制作项目清单多列,并设置一些最大高度,以项目列表(我认为这种方法是可以接受的)(按部门菜单查看亚马逊左侧商店)。

  5. 使用jqueryUI根据做简短和分类你的项目列表(不错,但有一些工作要做)。 http://jqueryui.com/accordion/

+0

谢谢您的建议。我喜欢3和4的想法。也许我会尝试一下。谢谢! – Alexxus

+0

欢呼!你不要把这个标记为答案,并且赚取我一些=) –

+0

其实你的答案对我来说是正确的,尽管高分的问题没有100%解决(请参阅我对Sowmya解决方案的评论)。最后,我采纳了你的建议。 4(种类))。我限制了预览中的项目数量,并在下方放置了一个“查看所有xx项目”按钮,该按钮链接到购物车。 – Alexxus

0

这里有一个更新的jsfiddle,使车去了注脚 - 看看这是你在找什么:

http://jsfiddle.net/PMabQ/20/

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: fixed; 
    bottom: 0; 
    background-color: yellowgreen; 
    z-index: 1; 
} 

#cart { 
    width: 100px; 
    position: absolute; 
    top: 0; 
    right: 0; 
    background-color: red; 
    z-index: 2; 
} 

#cartItems { 
    display: none; 
} 
+0

它对我来说看起来不太合适:使用position:固定在#footer上。我想知道为什么#主div没有被缩放到身体的100%高度。 – Alexxus

0

更改页脚位置从#cart和使用

1

删除

并添加overflow:auto#main,使其根据车项目增加。

* { 
    margin:0; 
    padding:0; 
} 

html, body { 
    height: 100%; 
} 

#main { 
    width: 900px; 
    min-height: 100%; 
    margin: 0 auto; 
    position: relative; 
    background-color: lightpink; 
    overflow:auto 
} 

#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; 
    float:right; 
    background-color: red; 
} 

#cartItems { 
    display: none; 
} 

DEMO

+0

这并不能解决页脚不能进入页面底部的问题。 –

+0

@DanielImms Ya正确。感谢您的确认。我相应地更新了答案 – Sowmya

+0

不错,更好地解决了我在+1上的工作。 –