在基于 Chromium 的浏览器上,用作 background-image 的缩小图像会被像素化,而在使用 <img> 标签显示时看起来会更加模糊。 有没有办法更改背景图像的渲染样式,使其看起来像标签中的显示? 我尝试了 image-rendering 属性,但它似乎不适用于 background-image。它在 Firefox 上看起来不错。
Brave 上的渲染示例,左边是 background-image,右边是 <img> 标签:
#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" />
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这似乎仅在同时应用
size:cover和position:center规则时才会发生。通过将object-fit更改为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"); }