如何停止背景-位置使背景图像不那么清晰?

问题描述 投票:1回答:1

我有一张1920x1080的JPEG背景图片,我在1920x1080的屏幕上使用。

它具有以下属性。

background-image: url(/bg.jpg);
background-attachment: fixed;
background-position: center top;
background-repeat: repeat;

在Chrome浏览器中 background-position: center top; 的背景是完美的缩放和锐利的。添加这个属性后,背景就会失去锐度。

诡异的是,如果浏览器宽度是奇数,图像就会完美锐利。所以1920x1080会有点模糊,但1919x1080会很完美。

在Edge和Firefox中,无论哪种情况下,背景图像都能完美缩放。

浏览器中的 background-position 由于某些浏览器上的滚动条,需要该属性来实现正确的定位。

我已经尝试过 image-rendering. 唯一能让我看清区别的属性是......"。pixelate但它造成了某些部位的撕裂。

我尝试了很多不同的属性组合(background-size),但我肯定会漏掉一些东西。

我的问题是题目。

如何阻止背景位置使背景图像不那么清晰? How to stop background -position making the background image less sharp?

但这个问题的答案也会解决我的问题,因为我认为这可能是一个 bug,或者至少是 Chrome 浏览器某个功能的后遗症。

如何阻止Chrome浏览器在定位背景图片时对其进行大小调整(或做其他事情)?

html css google-chrome background background-image
1个回答
1
投票

发生这种情况可能有多种原因。

我猜测说背景尺寸没有被设置。我想把这个设置为 "背景尺寸"。background-size: contain 以保持你的比例。此外,当你使用 background-attachment: fixed; 确定div position: static.

希望能帮到你,如果没有,提供一个jsfiddle,我可以看看。

© www.soinside.com 2019 - 2024. All rights reserved.