将可滚动的div放在可变高度的固定div下 [英] Placing a scrollable div below a fixed div of variable height

查看:209
本文介绍了将可滚动的div放在可变高度的固定div下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于jquery mobile中的移动页面

This is with respect to a mobile page in jquery mobile

我在父div(data-role = header)中有两个div如下:

I have 2 divs as follows within a parent div(data-role=header)

<div data-role="header">
<div class="inner-topHeader-panel"></div>
<div class="inner-centercontent"></div>
</div>

我想inner-topHeader-panel是一个固定的位置可变高度)和内中心内容放置在inner-topHeader-panel下面并且是可滚动的。滚动时,向上滚动的部分应隐藏在inner-topHeader-paneldiv后面。

I want "inner-topHeader-panel" to be a fixed in position(note: it is of variable height) and "inner-centercontent" to be placed below "inner-topHeader-panel" and be scrollable. When scrolled, parts of it that is scrolled up should be hidden behind the "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如下,它工作!

solution: Thanks @LessQuesar,@ezanker and @mainguy, I set second div's css as follows and it worked!

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

并且我设置.inner-centercontent的顶部位置使用jQuery根据高度.inner-topHeader-panel

and i set the .inner-centercontent's top position using jQuery according to the height of .inner-topHeader-panel

推荐答案

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

只有在高度小于内容时才会滚动。

Will only scroll when height is smaller than inner content.

这篇关于将可滚动的div放在可变高度的固定div下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆