Troubleshooting: Why is my CSS background image URL not displaying?

I'm struggling to understand why the background image is not showing up. However, when I use content:url(), it does appear. The issue with using content:url() is that I can't control the size of the image. Below, you will find the complete code for your reference.

Component

@Component({
      selector: 'app-reset-password',
      template: `
      <form>
      <h2 class="dialog-form-title">RESET PASSWORD</h2>
      <div class="warning-messages"><span class="warning_image">This User ID will no longer be able to log in with their 
      previous password.</span></div>
      <div class="dialog-form-footer" fxLayoutGap="20px">
        <button mat-flat-button type="submit" [mat-dialog-close]="true" style="margin:5px;background:#2BA9F8;">Confirm</button>
        <button mat-flat-button type="button" [mat-dialog-close]="false" style="margin:5px;background:#D3D3D3">Cancel</button>
      </div>  
    </form>
      `,
      styles: ['.warning-messages{background-color: #FFFEEF; color: #D9B88A; padding: 20px 10px; margin-bottom: 10px; font-weight: 400; }.warning_image:before{background-image: url("https://cdn1.iconfinder.com/data/icons/crime-and-security-3-5/48/147-128.png");}.warning_image:before{display: inline-block;vertical-align: middle;background-size: 12px auto;}']
    })

This DEMO showcases the functionality.

Answer №1

To implement a pseudo element, it is necessary to specify the content property. Instead of using the before selector, you can directly assign a background image to the warning-messages class.

.warning-messages{
  background-image: url("https://cdn1.iconfinder.com/data/icons/crime-and-security-3-5/48/147-128.png");
  background-repeat: no-repeat;
}

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

Implementing Expand/Collapse functionality for multiple TableRow components in Material-UI

Using a Material UI table and attempting to expand the `TableRow` inside a collapse table, but encountering an issue. Currently, all collapses are connected to one state for "open," causing all lists to open if one is clicked. What is the optimal approach ...

Cloning objects in Angular v2 and above using TypeScript with getters

Is there a way to efficiently duplicate a TypeScript class without losing getters and ensuring that nested classes and array items have new references? I have attempted using JSON.parse(JSON.stringify(obj));, but this method does not copy the getters. On ...

Encountered a null value when executing methods for the second time in an Angular application

I am facing an intriguing issue with a fragment of my app's code. CategoriesPageComponent: export class CategoriesPageComponent implements OnInit { private categories: Array<Category> = []; public randomizedCategories: Array<Category&g ...

Element statement is not responding correctly on hover when combined with an if statement

Desperately seeking some JQuery assistance here. I feel like tossing my laptop out the window. After countless hours of coding, I've hit a roadblock that's driving me crazy. I'll only share the relevant portions of the code since it's ...

What is the best way to loop through an array of JSON data in order to consistently retrieve the initial JSON object?

How can I retrieve only the full highlight videos from the JSON object in the video array? { "response": [ { title: "United vd Chelsea", "videos": [ { "title": "Highlights&quo ...

Apply a blurred effect to the entire website except for one specific element

Recently, I implemented the .blur class on the body element to create a blurred effect for the entire website. CSS .blur { filter: blur(1px); filter: url("blur.svg#gaussian_blur"); -webkit-filter: blur(1px); -o-filter: blur(2px); } HTML ...

How can I arrange multiple images within a div to create a circular view?

How can I create a div block with multiple images positioned inside? I'm having trouble applying div CSS properties to the images, and also want them to be displayed in round shapes. ...

Dealing with JSON data in the format of `(Object object)` requires a specific approach

I originally encountered object object when attempting to display JSON API data in HTML. I then used keyvalue in *ngFor which allowed me to display the object, but I am wondering how I can access and display the entire JSON data? Here are the relevant cod ...

What could be causing the gap between the top row and the navbar when using Bootstrap 4?

I'm struggling to identify the source of a space or gap in my header section called #contact-stripe that separates it from the navbar. Despite checking for padding or margin settings, I couldn't pinpoint the issue. For better visibility, I' ...

Clicking the Bootstrap NavBar Collapse does not trigger the expected functionality

I'm having some issues with the collapse button in my navbar. Whenever I click on the navbar button, the collapsible section doesn't open. I suspect that there might be an issue with the data-toggle function not properly toggling the collapse. ...

CSS causing unexpected behavior in image slider

I am facing an issue with incorporating a code for an image slideshow into my website. The current CSS is causing the slideshow to malfunction. Without the slideshow code in the CSS, the image appears correctly on the screen and changes its source every 2 ...

Injecting ngx-bootstrap modules into a child module in Angular 4: Step-by-step guide

My current application folder structure is set up as follows: >app app.module.ts app.routing.ts >>auth login.component auth.module.ts atuh.routing.module.ts Now, I have a requirement to incorporate the ngx-intl-input module into my pro ...

The background appears only in the upper portion of the screen upon refreshing the table

Whenever the user clicks on the edit button or when the page is initially loading, a backdrop appears and disappears once the modal is displayed. The backdrop effectively highlights the entire page. However, after updating my table with data via Ajax witho ...

Unraveling NGRX: a guide to invoking factory selectors from within additional selectors

NGRX has deprecated selectors with props in version 11. The recommended method now is to create factory selectors. How can you nest selectors or call one from another and pass the state between them? Prior to the change, if we had the following two selec ...

Experience a seamless front/back DIV transition with a mouseover effect similar to the ones on USAT

Recently, I was tasked with creating a mouseover transition effect for a div similar to the one used on USAToday's website. The structure of the boxes on the site includes: <div class="asset"> <div class="front">'image and some t ...

Tips for dynamically resizing an image to suit any screen size, such as with Bootstrap 4

I am having trouble centering an image on the screen and making sure it fits properly without requiring the user to scroll (on screens larger than a tablet). Here is my desired outcome: https://i.sstatic.net/LbfV8.png The top row shows the expected resu ...

Mobile and tablet screen resolutions determine the position of the navigation toggle button

I've been stuck on this issue for days now and would really appreciate some help sorting it out. I'm trying to position the hamburger icon on the right side, a contact picture with a phone number in the middle, and a brand logo on the left. For s ...

Nightwatch is a tool that allows you to interact with elements on a webpage by clicking on an element within

I have a scenario on my website where I have two separate div elements: <div class="wg-block" data-reactid="10" <div class="wg-header" data-reactid="11"/div> .... <h4 class='condition'> "Text" </h4> <div cl ...

Error message stating NullInjectorError with NgxSpinnerService; encountered No provider for t while attempting to host on Firebase

As I attempt to deploy my app on Firebase, everything functions properly in localhost. However, upon successful hosting on Firebase at the Firebase domain, an issue arises: NullInjectorError: StaticInjectorError(wo)[class{constructor(t,e) at SpinnerServic ...

Having trouble with Angular Ng2-file-Upload's Upload.all() method not successfully sending files to the API

Dealing with the challenge of uploading files in mp4 and jpg formats, I have set up 2 separate instances of FileUploader with custom validation. Upon clicking the upload button, I attempt to merge the files from both instances into a single FileUploader ...