html - 为侧边栏和主要内容创建高度的问题
问题描述
我正在尝试为我的管理页面创建侧边栏和主要内容的高度,但由于某种原因,它仅在我的标题之后创建顶部的高度,并且不适用于右侧、左侧或底部,所以我无法将任何 CSS 应用到我的侧边栏和主要内容。我正在关注本教程https://youtu.be/kGzwvOFUewY(16:00 是我想要实现的目标)。我的代码与他的相同,但由于某种原因它仍然无法正常工作,所以我很困惑。
我的 HTML 是:
<div class="admin-wrapper">
<div class="left-sidebar">
</div>
<div class="admin-content"></div>
</div>
而 CSS 是:
.admin-wrapper{
display: flex;
height: calc(100% - 66px);
}
.admin-wrapper .left-sidebar{
flex: 2;
height: 100%;
border: 1px solid red;
background: #a94442;
}
.admin-wrapper .admin-content{
flex: 8;
height: 100% ;
border: 1px solid green;
}
解决方案
你可以像那样做...
.admin-wrapper{
display: flex;
height: 100vh;
flex-direction: column;
}
.adminHeader {
display: flex;
width: 100%;
background: blue;
color: #fff;
padding: 10px;
}
.bodyContent {
display: flex;
height: calc(100vh - 50px);
}
.admin-wrapper .left-sidebar{
height: 100%;
border: 1px solid red;
background: #a94442;
width: 25%;
}
.admin-wrapper .admin-content{
height: 100% ;
border: 1px solid green;
}
<div class="admin-wrapper">
<div class="adminHeader">Admin Header</div>
<div class="bodyContent">
<div class="left-sidebar">
</div>
<div class="admin-content"></div>
</div>
</div>
推荐阅读
- cookies - ExpressionEngine 5 - Cookie 同意解决方案
- javascript - @Html.ActionLink 语言
- python - 以 Python 方式使用不同的函数
- c++ - 打印我的向量不起作用(没有编译器错误)
- sql - 查询以查找唯一行及其计数
- amazon-web-services - 无法让 aws lambda 通过 aws sns 发送短信
- python - 我创建的变量在另一个函数中不起作用
- wordpress - 如何显示带有插件(高级自定义字段)字段组的帖子?
- javascript - 可能的最短总距离停车场算法
- spring-boot - Spring boot JMS DefaultListenerContainer 偶尔会断开连接并且不会使用 Tibco EMS 自动撤销