How to fix pixelated background images on Chromium-based browsers?
P粉549412038
P粉549412038 2024-03-19 21:10:42
0
1
383

On Chromium-based browsers, reduced images used as background-image will be pixelated and will look more pixelated when displayed using the <img> tag Vague. Is there a way to change the rendering style of the background image so that it looks like it is displayed in the label? I tried the image-rendering property but it doesn't seem to work with background-image. It looks good on Firefox.

Rendering example on

Brave with background-image on the left and <img> on the right Tags:

#backgroundImage, img {
  width: 80px;
  min-height: 80px;
  margin: 10px 5px;
  display: inline-block;
}

#backgroundImage {
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  background-image: url("https://i.stack.imgur.com/X5EfB.png");
}
<div id="backgroundImage"></div>
<img src="https://i.stack.imgur.com/X5EfB.png" />

P粉549412038
P粉549412038

reply all(1)
P粉649990273

This only seems to happen when both the size:cover and position:center rules are applied. You can get the same result in by changing object-fit to cover:

#backgroundImage, img {
  width: 80px;
  min-height: 80px;
  margin: 10px 5px;
  display: inline-block;
  object-fit: cover;
}

#backgroundImage {
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  background-image: url("https://i.stack.imgur.com/X5EfB.png");
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template