html - 高度 : 100% to use the remaining height?

标签 html css

红色的是标题。 然后我有 5 行,我想在其中使用剩余空间的 20%。 但是它占用了 20% 的窗口空间。如何解决?

enter image description here

html:

<div id="container">
    <div id="header"></div>
    <div id="items">
        <div class="item" id="item1"></div>
        <div class="item" id="item2"></div>
        <div class="item" id="item3"></div>
        <div class="item" id="item4"></div>
        <div class="item" id="item5"></div>
    </div>
</div>

CSS:

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden; 
}

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

#header {
    position: relative;
    width: 100%;
    height: 10%;
    background: red;
}

#items {
    position: relative;
    width: 100%;
    height: 100%;
}


.item {
    height: 20%;
    width: 100%;
}

#item1 {
    background: green;
}

#item2 {
    background: blue;
}

#item3 {
    background: orange;
}

#item4 {
    background: purple;
}

#item5 {
    background: brown;
}

http://jsfiddle.net/clankill3r/dabrm8js/

最佳答案

#items {
    position: relative;
    width: 100%;
    height: 90%;
}

10% 被标题占用,所以你有 90% 的高度用于元素(而不是全部 100%)...

关于html - 高度 : 100% to use the remaining height?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29602522/

相关文章:

javascript - 使用 javascript 验证 PHP 表单

javascript - 如何在JavaScript中动态填充表中获取td的innerHTML

javascript - 使固定的 div 不水平滚动?

html - 将 CSS 样式应用于 DIV 内的所有元素

html - 投影效果不起作用

javascript - 如何让我的按钮不可点击

javascript - 是否可以使用 javascript 制作连续计数/工作日历?

javascript - 如何在按 Enter 时重新加载输入标签所在的特定 div

html - Quill 编辑器输出不显示换行符

html - div类显示:none not working