首页 > 解决方案 > 如何使侧边栏占据我们网页的所有高度?

问题描述

这是我当前的侧边栏:

侧边栏

我希望它总是占据所有的高度,请问怎么办?

我已经测试了 height: 100% 但它在这里不起作用是我的 css 代码:

#sidebar {
    /* don't forget to add all the previously mentioned styles here too */
    min-width: 250px;
    max-width: 250px;
    min-height: 100vh;
    /*background: #7386D5; */
    background-color: rgb(31, 40, 55);
    color: #fff;
    transition: all 0.3s;
    float: left;
    height : 100%;
}

标签: htmlcssbootstrap-4sassangular-material

解决方案


height: 100%将使其占据容器高度的 100%。尝试使用position: fixedposition: absolute使其占据屏幕高度的 100%:

#sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 250px;
}

推荐阅读