html - 即使在 min-height:100% 处也没有填写 Div;
问题描述
所以我目前对 Angular 整体还是很陌生,所以我的 CSS 知识不是太大,我尝试为自定义侧边栏填写 div,但除非我在 div 中添加某种内容,否则它不会实际上填写min-height: 100%;
我开始的内容height: 100%,
,我已经尝试height: auto;
过以及删除填充和边距。
通向我的路由器插座,它通向我的 SideBar 组件
样式.css
html {
min-height: 100%;
overflow: hidden;
}
body {
min-height: 100%;
background-image: url('assets/Images/HomeBack.jpg');
background-repeat:no-repeat;
background-position: right top;
background-size: 539px 360px;
overflow: hidden;
}
索引.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DadWebsite</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
SideBarTest.component.html
<div class="page-continer">
<div class="sidebar">
<p>HELLO</p>
</div>
</div>
SideBarTest.component.css
.page-container
{
min-height: 100%;
}
.sidebar
{
min-height: 100%;
width: 300px;
background: orange;
}
SideBarTest.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-SideBarTest',
templateUrl: './SideBarTest.component.html',
styleUrls: ['./SideBarTest.component.css']
})
export class SideBarTestComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
解决方案
当您使用height: 100%
侧边栏时,它将是其父组件的 100%。侧边栏的父级是body所以它会占用 body 的100 %高度。
body的父级是html,但您没有为它添加高度。
第一种方法
添加html标签的高度。
html {
height: 100%
}
第二种方法
用于主体或侧边栏height: 100vh
,使侧边栏的高度等于视口的高度,即浏览器的全高。在我看来,如果你将它添加到正文中会更好。
100vh
表示视口高度的 100%。
推荐阅读
- android - dependencies error when add firebase libraries
- c# - 如何将本地目录路径存储在数据库中?
- javascript - 如何插入正确显示无
- r - 将 XML 转换为数据框
- javascript - 如何在 Angular 中将 JS 文件包含到组件中
- excel - 在 Excel 中,需要匹配每行中的数字并添加包含匹配项的单元格数
- authentication - Elm 中的惯用身份验证
- ruby - 线程中的 Ruby 线程
- django - 使用 Angular 登录页面寻找有关 Django 身份验证的帮助
- c# - .NET Core 控制台应用程序无法在 Windows Server 上运行