you can also set property for body using before and after pseudo elements.
body:before{
position:absolute;
top : 0;
left: 0;
width: 100%;
height: 100%;
background-color: black;
content:"";
pointer-events: none;
z-index:100;
opacity: .5
}
You could use an overlay - another div the full size of the screen that covers the html, with the bonus of giving a translucent grey shadow over the body.
In this example, use two divs.
One is the overlay, and the other (inside the overlay for convenience) is the modal.
<div class="overlay">
<div class="modal">
This is the modal. You can put whatever you like in here.
</div>
</div>
Now the overlay needs styles:
.overlay {
position: fixed; /* Positioning and size */
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(128,128,128,0.5); /* color */
display: none; /* making it hidden by default */
}
and the modal needs some too:
.modal {
position: fixed; /* positioning in center of page */
top: 50vh;
left: 50vw;
transform: translate(-50%,-50%);
height: 400px; /* size */
width: 600px;
background-color: white; /* background color */
}
Include jQuery by putting this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
In the head tag at the top of your code.
Then, use this button to open the modal:
<button onclick="$('.overlay').show();">Open modal</button>
and this jQuery code to catch click on the overlay but not its child.
$('.overlay').on('click', function(e) {
if (e.target !== this) {
return;
}
$('.overlay').hide();
});
$('.overlay').on('click', function(e) {
if (e.target !== this) {
return;
}
$('.overlay').hide();
});
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(128,128,128,0.5);
display: none;
}
.modal {
position: fixed;
top: 50vh;
left: 50vw;
transform: translate(-50%,-50%);
height: 400px;
width: 600px;
background-color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<a href="https://www.google.co.uk">This is a link, but with the modal open you can't click it!</a>
<br>
<br>
<button onclick="$('.overlay').show();">Open modal</button>
<div class="overlay">
<div class="modal">
This is the modal. You can put whatever you like in here.
</div>
</div>
The following would make a screen-filling element that also adds blur.
.bg{
position: fixed;
top: 0;
left: 0;
z-index: 1040;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.4);
backdrop-filter: blur(15px);
}
I guess you've missed the property MatDialogConfig - backdropClass in the docs.
Check this StackBlitz DEMO for a simple example
From this DEMO:
dialog-overview-example.ts:
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal},
backdropClass: 'backdropBackground' // This is the "wanted" line
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
styles.css:
.backdropBackground {
/* your css needs */
}
You need to alter the structure of your document first. It should look something like this
<body>
<div class="supreme-container">all your content goes here except for the modal</div>
<div id="myModal" class="modal fade">This is your modal.</div>
</body>
And then in css
body.modal-open .supreme-container{
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-o-filter: blur(1px);
-ms-filter: blur(1px);
filter: blur(1px);
}