简体   繁体   English

div内容的最大高度

[英]Max-height of div content

Take a look at this fiddle: https://jsfiddle.net/cz1gusj6/1/ 看看这个小提琴: https : //jsfiddle.net/cz1gusj6/1/

What i want to do is this bars to fit the screen size height, always. 我想做的是,此条始终适合屏幕尺寸的高度。

This is the page: http://cl.ly/image/0o0e1W0X0n2Z/1-browser.jpg 这是页面: http : //cl.ly/image/0o0e1W0X0n2Z/1-browser.jpg

This is what happens when i change the window height: http://cl.ly/image/410z3E0l420K/2-browser.jpg 当我更改窗口高度时,会发生以下情况: http : //cl.ly/image/410z3E0l420K/2-browser.jpg

This is what i want it to happen when i change the window height: http://cl.ly/image/0P3u1r0F2P1r/3-browser.jpg 这是我希望在更改窗口高度时发生的情况: http : //cl.ly/image/0P3u​​1r0F2P1r/3-browser.jpg

I tried to assign a max-height to the div but that does not work because the content it's not images: 我试图为div分配最大高度,但是由于内容不是图片,因此无法正常工作:

#container{
width: 100%;
height: 100%;
}

.container2{
max-height: 100%;
}

<div id="container">
<div class="container2">CONTENT (the bars)</div>
</div>

jsBin demo jsBin演示

Simply set your bars to a vh ( viewport height ) unit size. 只需将条形设置为vh视口高度 )单位即可。

Also you cannot have multiple ID inside a single page! 同样,您不能在单个页面中拥有多个ID! id="progressbar" should be unique! id="progressbar"应该是唯一的! So use class . 因此,使用class . .

Since you use vh now, don't use <br> tags, rather a margin (also in vh ). 由于您现在使用vh ,因此请勿使用<br>标签,而应使用margin(也在vh )。
Set the Child of your progressbars to height:100%; 将进度条的子级设置为height:100%; (to fill the parent height) (填满父母身高)

If you have fixed number of bars, read on (I'm using 10 bars as an example). 如果条数固定,请继续阅读(我以10条为例)。

DEMO: http://jsfiddle.net/8yrp8d9u/ 演示: http : //jsfiddle.net/8yrp8d9u/

HTML HTML

<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>
<div class="progressbar"><span></span></div>

CSS CSS

html, body {
    height: 100%;
}
body {
    background: #4086a4;
    margin: 0;
}
.progressbar {
    margin: 0 auto;
    width: 30%;
    height: 10%;
    box-sizing: border-box;
    border: 10px solid #4086a4;
    border-width: 5px 0;
    background: #7aabbf;
}
.progressbar span {
    display: block;
    width: 0;
    max-width: 100%;
    height: 100%;
    background: white;
    -webkit-animation: progress 2s 1 forwards;
    -moz-animation: progress 2s 1 forwards;
    -ms-animation: progress 2s 1 forwards;
    animation: progress 2s 1 forwards;
}
@-webkit-keyframes progress {
    from {} to {width: 100%}
}
@-moz-keyframes progress {
    from {} to {width: 100%}
}
@-ms-keyframes progress {
    from {} to {width: 100%}
}
@keyframes progress {
    from {} to {width: 100%}
}

change container2 to: 将container2更改为:

.container2{
    max-width: 100%;
    max-height: 100%;
    bottom: 0;
    left: 0;
    margin: auto;
    overflow: auto;
    position: fixed;
    right: 0;
    top: 0
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM