[英]Adding background-image to mat-dialog
I am trying to add background-image to mat-dialog, by spending some time on mat-dialog docs I realised that I can use panelClass: 'my-class'
, to customize mat-dialog appearance, here my-class
end up getting applied to div having class cdk-overlay-pane
in mat-dialog, something like this.我正在尝试将背景图像添加到 mat-dialog,通过在 mat-dialog 文档上花费一些时间,我意识到我可以使用panelClass: 'my-class'
来自定义 mat-dialog 外观,在这里my-class
最终得到应用于在 mat-dialog 中具有类cdk-overlay-pane
div,类似这样。
Then I added this css to put the background-image in the matt-dialog.然后我添加了这个 css 来将背景图像放在 matt-dialog 中。
.my-class .mat-dialog-container {
background: url("assets/illustrations/abc.svg") no-repeat;
padding-bottom: 16px !important;
}
.my-class {
// background: white !important;
border-radius: 10px;
}
eventually mat-dialog ended up looking like this, having transparent background.最终 mat-dialog 最终看起来像这样,具有透明背景。
In order to solve this issue I ended up adding background: white;
为了解决这个问题,我最终添加了background: white;
to my-class
and then it looked like this.到my-class
,然后它看起来像这样。
Everything seems to work fine, but it is now bit-buggy as soon as I close the dialog a white background of the same size is theres for milliseconds and then it disappears.一切似乎都运行良好,但是一旦我关闭对话框,它就会出现问题,相同大小的白色背景会持续几毫秒,然后消失。
I managed to solve the problem by changing the way I was doing it, sometimes it's easier to change the approach instead of trying to find the solution of situation that you are struck on.我设法通过改变我做事的方式来解决这个问题,有时改变方法比试图找到你遇到的情况的解决方案更容易。
what I did is as follows.我所做的如下。
In the attached image div having class='content represents the content of the dialog-box, so it's basically a div
that we place as a wrapper on the content we want to display in mat-dialog, in my case I named it content
.在附加的图像 div 中, class='content表示对话框的内容,因此它基本上是一个div
,我们将其放置为要在 mat-dialog 中显示的内容的包装器,在我的情况下,我将其命名为content
。
So I modified the .mat-dialog-container padding to 0, so that content div can take the full height and width
, and then added background-image
to content div.所以我将.mat-dialog-container padding 修改为0,这样content div 就可以取全height and width
全height and width
,然后将background-image
添加到content div 中。
.my-class .mat-dialog-container {
padding: 0px !important;
}
Final outcome can be seen in the below-mentioned image.最终结果可以在下面提到的图像中看到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.