- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
I have a page without vertical scroll on element. I mean no matter how you zoom - it will adjust to screen size and there always be
我在
顶部的红色div(内部内容),高度固定
底部动态扩展高度绿色div(其高度取决于内部内容)。
在这些div之间还有1个div,其中2个孩子(黄色背景)具有可滚动内容。这个div应该流动其余的空间。
To remove page's scroll I just feet the html height perfectly to its inner elements sum by using height: calc(100% - 83px)
where 83px
is top and bottom divs height sum. But here's a problem: when the bottom div's height increases I need to change scrollable center div's height with Javascript. I want to solve this only using css
. Here's jsfiddle and the picture described by layout. What I found so far:
要删除页面的滚动,我只需使用height:calc(100% - 83px)将html高度完美地放到其内部元素总和,其中83px是顶部和底部divs高度总和。但是这里有一个问题:当底部div的高度增加时,我需要用Javascript改变可滚动的中心div的高度。我想用css解决这个问题。这是jsfiddle和布局描述的图片。到目前为止我发现了什么:
overflow:auto;
for children and a tricky ?height: 100%
and children must have `height: 100%'我认为父div应该有某种溢出:auto;对于儿童和一个棘手的?身高:100%,儿童必须有'身高:100%'
我不能使用绝对位置,因为我不知道中央div应该从哪里开始和垂直结束
The code is listed below:
代码如下:
1 个解决方案
#1
1
I think you are looking for a flex-box solution. It requires some love and care to get it to work on all modern browsers so take a look at caniuse.com for info about this.
我认为您正在寻找一个灵活的解决方案。它需要一些爱和关心才能让它在所有现代浏览器上运行,所以请查看caniuse.com获取有关此信息的信息。
It is worth pointing out that this does not work with old browser version at all and that a Javascript substitute will be required if support is essential.
值得指出的是,这根本不适用于旧的浏览器版本,并且如果支持必不可少,则需要Javascript替代品。
html,body{
height:100%;
margin:0;
}
#wrapper{
height:100%;
display:flex;
flex-direction:column;
}
#header{
height:50px;
background-color:red;
}
#content{
flex:1;
display: flex;
background-color:yellow;
}
.scrollable{
width: 50%;
overflow-y:auto;
float:left;
display:inline-block;
}
#footer{
background-color:green;
}
Header
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
Content