html - 如何使侧边栏占据我们网页的所有高度?
问题描述
这是我当前的侧边栏:
我希望它总是占据所有的高度,请问怎么办?
我已经测试了 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%;
}
解决方案
height: 100%
将使其占据容器高度的 100%。尝试使用position: fixed
或position: absolute
使其占据屏幕高度的 100%:
#sidebar {
position: fixed;
top: 0;
bottom: 0;
width: 250px;
}
推荐阅读
- mysql - 将本地数据库连接到另一个在线数据库
- python - python中的相对地址
- node.js - Node + Express 如何访问上传文件夹
- java - 从 JHipster 生成的应用程序中删除授权
- python - python中的OS函数读取文件
- c - “#define __SIZE_T”和“typedef unsigned int size_t”
- kivy - TypeError:不能在 python 的路径组件中混合字符串和字节
- c++ - 最近 googletest 中的 ColoredPrintf
- javascript - 移位运算符仅在移位到 16 位时有效
- reactjs - 无法让探查器在 dev 或 prod 上工作