角材料垫抽屉问题与高度

时间:2019-01-22 07:48:21

标签: javascript html css angular angular-material

由于某种原因,我似乎无法让垫子抽屉占据屏幕上剩余的可用高度。我尝试过:

.drawer-container {
    position: fixed;
    height: 100%;
    min-height: 100%;
    width: 100%;
    min-width: 100%;
}

但是由于滚动条指示,尽管屏幕上只有一个元素,但由于某些原因,我仍然会溢出:

enter image description here

当我删除CSS规则时,最终得到的是:

enter image description here

基本上仅占屏幕高度的10%。我已经考虑过使用固定的高度,但是我猜测如果在更大或更小的显示器上观看,它会看起来像是被切断了。我将不胜感激,因为我对角材料的全部属性以及如何正确操作它们并不真正熟悉。提前致谢。

2 个答案:

答案 0 :(得分:0)

以防万一,并且有类似问题。 我很早以前通过应用

来解决此问题
.drawer-container {
  position: absolute;
  top:0;
  width: 100%;
  bottom: 0;
}

只需确保父母有position: relative

答案 1 :(得分:-1)

我想mat-sidenav还不支持基于百分比的宽度/高度。

尝试height: 100vh;

应该可以,但是如果页面中有任何工具栏,则会添加一个滚动条。

更新:

HTML:

<mat-drawer-container class="parent" autosize>
        <mat-drawer mode="side">
            Your sidenav content
        </mat-drawer>

        <div class="content">
            Your main content.
        </div>
</mat-drawer-container>

CSS:

.parent {
    width: 100%;
    height: 100vh;   // calc(100vh - 64px) can be used if there is navbar at the top
}

.content {
    height: 100%;
}