Incorporating a background image into a mat-dialog

After spending some time on the mat-dialog documentation, I discovered that I can add a background image to the mat-dialog using panelClass: 'my-class' to customize its appearance. This applies the class my-class to the div with the class cdk-overlay-pane within the mat-dialog.

https://i.sstatic.net/Zjn6G.png

I then added the following CSS to include a background image in the mat-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;
}

As a result, the mat-dialog ended up with a transparent background.

https://i.sstatic.net/swv9r.png

To address this issue, I added background: white; to my-class, and the mat-dialog then appeared like this.

https://i.sstatic.net/2asFH.png

Although everything seemed to be working fine, there was a minor bug where a white background of the same size briefly appeared upon closing the dialog before disappearing.

Answer №1

I found a solution to the problem by changing my approach. Sometimes, it's more effective to alter the way we are tackling a problem rather than getting stuck trying to find a solution.

Here's what I did:

In the image attached, the class='content' in a div represents the content of the dialog-box. It serves as a wrapper for the content to be displayed in the mat-dialog, named content in my case.

https://i.sstatic.net/rtNvc.png

To make the content div take up the full height and width, I adjusted the padding of the .mat-dialog-container to 0 and added a background-image to the content div.

.my-class .mat-dialog-container {
  padding: 0px !important;
}

You can view the final result in the image linked below.

https://i.sstatic.net/ZmpbC.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Rotation using CSS in Internet Explorer 8

Can anyone help me with a CSS solution for rotating elements in IE8? I've tried some solutions that claim to work in IE8, but they're not working for me. What am I doing wrong? Here's what I've attempted: <!DOCTYPE html> <htm ...

The Angular router is throwing a "TS2339: Property 'navigate' does not exist on type 'Route'." error message

I'm really struggling with this issue. Why is the 'navigate' property not available to use? When attempting to use it, I receive the error message "TS2339: Property 'navigate' does not exist on type 'Route'." For more in ...

An issue within the component.ts file is preventing Angular from correctly rendering the content

As a newcomer to Angular, I encountered an issue when trying to run my angular app. Instead of displaying the content as expected, all I see is a blank page. Upon inspecting it, I noticed that the app-root element was empty. So, I decided to take a look at ...

Angular 13.0 version is experiencing issues when trying to run the "ng serve" command

After installing the npm module, I encountered a problem while using node.js version 14.17.6. I am a beginner in Angular and struggling to find a solution due to not using the latest Angular CLI version. Any help would be greatly appreciated. Thank you in ...

Understanding JavaScript for Reading a Website's "Local Storage"

Can the local storage of one website be accessed by a different domain, or is it restricted to only the domain that saved it? ...

Toggle switch with active state

I'm currently using Ionic 2 alongside Angular 2 beta 11. Is there a way to turn off the toggle switch? The Ionic documentation suggests using the checked attribute, but I've tried that and also attempted ng-checked with no luck. Any advice on t ...

Resolving the active tab problem within Angular 2 tab components

Can anyone assist in resolving the active tab problem within an angular 2 application? Check out the Plunker link I am using JSON data to load tabs and their respective information. The JSON format is quite complex, but I have simplified it here for cla ...

Issue with jQuery's .height() method not updating

Here is the code I am working with: $(function() { $('#team-ch').click(function() { $('#team-camb-hert').height('auto'); }); }); I am trying to change the height of a div when a link is clicked. After adding an alert ...

Developing a custom mixin to alert a banner at the top of the webpage

I currently have a feature on my website that triggers a pop-up notification whenever a message is received from another user. The pop-up consists of a div displaying the content of the message along with a close button. After exploring various methods to ...

Tips for aligning input vertically across rows with bootstrap 5

I'm currently working on a form layout where each row contains a different number of columns, with labels and inputs in each column. However, I'm facing an issue where the start of the input is not aligned vertically for each row. I tried using ...

Encountering an error stating "ngbCollapse" is not a recognized property of "div" after relocating components to a sub module

Error compiler.js:215 Uncaught Error: Template parse errors: Can't bind to 'ngbCollapse' since it isn't a known property of 'div'. ("][ngbCollapse]="isHidden" In the process of organizing my code, I encountered an issue ...

What are the steps to display Firestore data on the server instead of the client side?

My objective is to display data on the server side. Expected outcome: the server should render the data. Actual outcome: the data is being rendered by the client instead of the server. The workflow follows this pattern Component -> call Use Case -> ...

navigating between html pages using sliding next and previous buttons

I am in the process of developing a multi-page form spread across 4 different pages. I would like to incorporate next and previous buttons to allow users to easily navigate through the form. Although I have tried looking online for solutions, most results ...

Converting Objects to Arrays with Angular Observables

After searching extensively on SO for answers regarding item conversions in Javascript/Angular, I couldn't find a solution that addresses my specific problem. When retrieving data from Firestore as an object with potential duplicates, I need to perfor ...

Enhance the appearance of your image by adding a stylish frame or border without altering its

Is there a way to add a frame to an image without causing it to shrink due to borders? Below is the code I have tried using: .img-border { height: 100%; width: 100%; position: absolute; z-index: 1; } <div class="border border-black i ...

Attempting to create a slider utilizing jQuery

I'm currently working on creating a slider using jquery. I have downloaded the cycle plugin for the slider and included it in my file. The slider consists of 7 pictures. Below is the code I am using, can someone please help me identify any issues? &l ...

A unique directive that showcases both default and custom errors sequentially

In my project, I am facing a challenge where I need to compare the input text with a series of inbuilt errors such as required, minlength, maxlength, and pattern. Additionally, I also need to validate the input against a custom condition using a Custom Val ...

What is the best way to verify observables during the ngOnInit phase of the component lifecycle?

Despite reading numerous articles on testing observables, such as learning how to write marble tests, I am still struggling to find a clear solution for testing a simple observable in the ngOnInit lifecycle of my component. ngOnInit(): void { this.sele ...

Merging two promises into a single promise in Angular

In my application, I am facing a challenge with implementing a method named loadAll. What I need to accomplish is to make calls to 2 different HTTP methods in order to load the necessary data. Both of these methods return promises. However, when I attem ...

Utilizing Javascript / jQuery to eliminate specific CSS styles

I am facing an issue with the CSS code for a table positioned at the bottom of the screen. The current code includes a filter specifically for IE 8, but I need to make it compatible with IE 10 as well by removing the filter and adding a background color. ...