css - 如何在较小的屏幕上调整 MAT DIALOG 的大小
问题描述
这是我的 component.html 文件:
<div class="button">
<button (click)="openPopUp()" mat-button class="readBtn">Buy Now</button>
</div>
这就是它的.ts文件。
openPopUp() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.width="60%";
this.dialog.open(GetBuyDetailsComponent, dialogConfig);
}
单击按钮时,我将打开名为GetBuyDetails的 Mat 对话框。但是这个 GetBuyDetails Pop-up 或 Mat Dialog 没有响应,因为它的宽度总是60%。如何使 Mat Dialog 组件具有响应性。
解决方案
好的,据我了解,您有两个解决方案。
根据文档,您有两种选择 - 您必须决定哪一种更适合您。
1. 覆盖panelClass
对话框。
这很容易实现,您可以将样式存储在组件目录中,解决方案如下:
组件样式.scss
::ng-deep .my-custom-panel {
width: 70%;
// your custom logic - this is a sketch
@media screen and (max-width: 660px){
width: 100%;
}
}
.component.ts
openPopUp() {
this.dialog.open(<your component>, {
disableClose: true,
autoFocus: true,
panelClass: 'my-custom-panel'
});
}
这里的主要问题是您不能将样式范围限定为组件,每种.my-custom-panel
样式都将被全局覆盖。
2.为此使用全局样式
可能会更好一些,但是您必须在全局styles.(s)css
中定义您的覆盖类,您应该在其中不使用::ng-deep
修饰符。从那时起,您可以简单地遵循前面的逻辑。
我将明确地选择第二个,因为Angular 不推荐::ng-deep
使用不带任何修饰符(例如:host
)的使用,这是一个不太好的解决方案。
希望这对您有所帮助,如果您有任何问题,请发表评论。
推荐阅读
- android - 如何延迟加载微调器并在协程内有条件地启动它?
- python - 比较两个 datetimestamp 列,如果该 datetimestamp 存在,则使用默认值创建新行 datetimestamp
- asp.net - 在 VS2015 和 VS2017 中打开解决方案时读取注册表的不同行为
- android - Xamarin.Android RecyclerView 提供数据库
- java - 获取特定程序的 JVM 属性
- c# - 在 Web 中检查 WCF 服务时出错
- pandas - 在 Pandas 中生成二项式排列
- cpython - 为什么 PySequence_GetItem 返回一个新的引用?
- testing - 选项不适用于跑步者
- mongodb - 通过 docker-composer 将 --wiredTigerCacheSizeGB 存储到 mongod.conf