【问题标题】:Make bottom sheet(popover) sticky to button (Angular material)使底部表(弹出窗口)粘在按钮上(角材料)
【发布时间】:2019-09-22 07:55:57
【问题描述】:

我有角形项目,我从角形材料添加底部片材,它可以工作。 我试图让打开的弹出窗口粘在按钮上并响应他但它不起作用。

我的主要组件:

import { Component, OnInit } from '@angular/core';
import { MatBottomSheet } from '@angular/material/bottom-sheet';
import { PopupsDialogComponent } from '../../../modules/home/components/popups-dialog/popups-dialog.component';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.sass']
})
export class HeaderComponent implements OnInit {

  constructor(private _bottomSheet: MatBottomSheet) { }

  ngOnInit() {
  }
  openBottomSheet(): void {
    this._bottomSheet.open(PopupsDialogComponent, {
      panelClass: 'custom-popup'
    });
  }
}

主要组件html: 这是我希望对话框对他来说很粘的按钮

<header>
  <div class="container">
    <button mat-fab class="mat-success" (click)=openBottomSheet()>+</button>
  </div>
</header>

PopupsDialogComponents:

import { Component } from '@angular/core';
import {MatBottomSheetRef} from '@angular/material/bottom-sheet';
@Component({
  selector: 'app-popups-dialog',
  templateUrl: './popups-dialog.component.html',
  styleUrls: ['./popups-dialog.component.sass']
})
export class PopupsDialogComponent {

  constructor(private _bottomSheetRef: MatBottomSheetRef<PopupsDialogComponent>) {}

  openLink(event: MouseEvent): void {
    this._bottomSheetRef.dismiss();
    event.preventDefault();
  }

}

style.css:

.custom-popup
    position: absolute
    top: 95px
    right: 26%
    min-width: 0% !important

非常感谢

【问题讨论】:

  • 你是否在你的主 sass/css 文件中导入了以下内容?(src/style.sass 或 css)@import '~@angular/material/prebuilt-themes/deeppurple-amber.css'
  • 你将样式应用到 top:95px 所以它会被定位在那里,有什么问题?
  • 哦,你的意思是按钮不是底部......(你的问题有一些错误)。我在几行中添加了 src/main.css .mat-bottom-sheet-container{ position: fixed !important; top: 27px !important; left: 0px !important; }
  • 当我调整屏幕大小时,弹出窗口获得新位置;(
  • 代替固定使用绝对

标签: css angular sass angular-material


【解决方案1】:

最近渲染了一些内置的角度组件, 我认为您可以在 CSS 中处理它,例如:

:host ::ng-deep .custom-popup {
    position: absolute
    top: 95px
    right: 26%
    min-width: 0% !important
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-28
  • 2016-02-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-21
相关资源
最近更新 更多