0

Web 应用程序具有以下结构,但滚动离开页面。任何想法出了什么问题?

http://jsfiddle.net/kYEES/

HTML

<div class="wrapper">
<div class="container">
  <div class="fixed-height">
    <p>Fixed height div</p>
  </div>

  <div class="scrolling-height">
    <p>Scrolling div</p>
  </div>
</div>
</div>

CSS

* {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.wrapper { 
  position: absolute;
  height: 100%;
  width: 100%;
}

.container {
  background: lightgray;
  height: 100%;
  overflow: hidden;
  padding: 10px;
  position: relative; 
}

.fixed-height {
  background-color: yellow;
  height: 40px;
  padding: 5px 10px;
}

.scrolling-height {
  background-color: green;
  bottom: 0;
  height: 100%;
  overflow-y: scroll;
  margin-bottom: 20px;
  padding: 5px 10px;
  position: absolute;
  top: 40px;
}
4

1 回答 1

0

像这样: http: //jsfiddle.net/DhWm5/3/ 我给了你的容器 aposition: relative和你的可滚动div的绝对位置:

.container {
    background: lightgray;
    height: 100%;
    padding: 10px;
    position:relative;
}
.scrolling-height {
    background-color: green;
    margin-bottom: 50px;
    overflow-y: scroll;
    padding: 5px 10px;
    position:absolute;
    top: 50px; bottom: 0;
}

top: 50px是为了允许固定高度div及其填充;

于 2013-04-26T15:36:07.527 回答