将可滚动div放置在可变高度的固定div下方

时间:2014-02-11 16:06:02

标签: jquery html css jquery-mobile

这是关于jquery mobile的移动页面

我在父div(data-role = header)

中有两个div
<div data-role="header">
<div class="inner-topHeader-panel"></div>
<div class="inner-centercontent"></div>
</div>

我希望“inner-topHeader-panel”是一个固定的位置(注意:它的高度可变)和“inner-centercontent”放在“inner-topHeader-panel”下面并且可以滚动。滚动时,向上滚动的部分应隐藏在“inner-topHeader-panel”div后面。

目前的CSS如下。

.inner-topHeader-panel{ 
    width:100%; 
    height:auto; 
    margin:0; 
    background:#fff; 
    border-bottom:none;
    float:left;
    position:fixed !important; 
    top:0;
}

.inner-centercontent{
  width:100%;
float:left;
 padding-bottom: 50px;
 }

溶液: 谢谢@ LessQuesar,@ ezanker和@mainguy,我设置了第二个div的css如下,它有效!

.inner-centercontent{ 
width:100%; 
height:100px;
overflow: hidden;
overflow-y: auto;
float:left;  
position:fixed !important;  
padding-bottom: 50px;
}

我根据.inner-topHeader-panel

的高度使用jQuery设置.inner-centercontent的顶部位置

2 个答案:

答案 0 :(得分:2)

pageshow上,计算固定div的高度,并将其下方div的margin-top设置为该值:

$(document).on("pageshow", "#page1", function(){
    var fixedH = $(".inner-topHeader-panel").outerHeight(true);
    $(".inner-centercontent").css("margin-top", fixedH + "px");
});
  

<强> DEMO

答案 1 :(得分:0)

CSS:

.inner-topHeader-panel {
  width: 100%;
  height: auto;
  margin: 20;
  background: white;
  border-bottom: none;
  float: left;
  clear: both;
  top: 0;
  z-index: 1000;
}
.inner-centercontent {
  width: 100%;
  float: left;
  height: 600px;
  overflow: scroll;
  padding-bottom: 50px;
}

Plunker

仅在高度小于内容时滚动。

相关问题