Image loading failed to replace image css solution

tags: css  Image failed to load  Image failed to load default image css  Default picture solution

img {
  position: relative;
}
 
img:after { 
  content: url('Alternative image');
  display: block;
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
}

This use should be some of the characteristics of the img tag:

1. img is a special tag, which has the same substitution as video. When the image is loaded successfully, the previously defined pseudo-class will lose its function without prompting.

2. The alt attribute will appear when the image fails to load (alternative text), so that the pseudo-class will work.

 

The common js solution is: through the onerror event of img, but it can be solved with css, why use js, haha

 

Learn from:

Intelligent Recommendation

CSS implementation of sprite image failed to load image

Failure prompt: 1. The console reports an error file not found. 2. The loaded pictures cannot be found in the images folder of the resource. Possible reasons for failure: 1. Image path error (most com...

Replace the bloody case caused by the image loading framework

I am going to change the image loading framework in the project today. Good guy, it’s a problem. Different image loading frameworks There are different APIs that cause me to change them. I regre...

Browser loading image error solution

In the past two days, I found that when the browser visited Baidu Post Bar or Baidu Experience, or even something on Baidu, I found that the pictures could not be loaded. as the picture shows. But whe...

Solution for image delay loading (for mobile)

2019 Unicorn Enterprise Heavy Glour Recruitment Python Engineer Standard >>> When the picture is more than the picture on the page, in order to optimize performance, delay loading technology ...

More Recommendation

ARXIV image loading slow solution

1. Use an oil monkey browser plugin 2. Then install "Continental Quick Download ARXIV Paper Insert in Plugments" 3. Replace the domestic mirror address to the Indian mirror address in the pl...

Docker image upload failed solution

Own packaged mirror, failed to upload Docker Hub, always prompt "denied: requested access to the resource is denied", the reason is simple:Docker account not logged in! "Please login pr...

Solve the problem of failed image loading in github

Open the hosts file under C:\Windows\System32\drivers\etc, and add the following fields at the end of the file: The first column above is the address, the second column is the domain name According to...

Image loading failed for vue custom command

When it comes to loading failure, onerror will be the first thing to think of, like this: This is no problem, but if you put dozens or hundreds of pages in the project, adding them one by one will be ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top