简体   繁体   English

CSS背景图片在移动设备上模糊

[英]CSS background images are blurred on mobile device

Setup: 设定:

<meta name="viewport" content="width=device-width, 
                      initial-scale=1, maximum-scale=1.0, user-scalable=no"/> 

I have created a 480 dpi sprite with buttons. 我用按钮创建了一个480 dpi的精灵。 Its dimensions are about 2000px * 1000px. 其尺寸约为2000像素* 1000像素。 In emulator with a css pixel ration of 2 which must be equal to 320 dpi the css images look fine. 在css像素比率为2(必须等于320 dpi)的模拟器中,css图像看起来不错。

.button-logo {
    background: url(../assets/img/sprite_480.png) no-repeat !important;
    background-position: -4px -139px !important;
    background-size: 790% !important;
}

However when I test them on real device with 320 dpi the images are blurred. 但是,当我在320 dpi的真实设备上测试它们时,图像模糊。 Any idea why the images get blurred on device? 知道为什么图像在设备上变得模糊吗?

When I add 当我添加

target-densitydpi=device-dpi

to meta tag the problem is fixed on device, however target-densitydpi was removed from webkit, see http://trac.webkit.org/changeset/119527 So I cannot use it. 要对标签进行元标记,该问题已在设备上修复,但是从webkit中删除了target-densitydpi,请参阅http://trac.webkit.org/changeset/119527,因此我无法使用它。

Any ideas how to solve this problem? 任何想法如何解决这个问题? I am building an application with phonegap for android 我正在使用phonegap为Android构建应用程序

This may help, when creating images for HD displays such as the retina display on an iPhone, the DPI isn't really the issue. 当为高清显示(例如iPhone上的视网膜显示)创建图像时,这可能会有所帮助,DPI并不是真正的问题。 It's more about the image size itself. 它更多地与图像大小有关。 If your button is going to display as 50x50 pixels then the image you create should be 100x100 pixels. 如果您的按钮将显示为50x50像素,则您创建的图像应为100x100像素。 Then in your CSS set the background-size:50px; 然后在您的CSS中设置background-size:50px;

It must be a 2x ratio in order for it to show crystal clear. 它必须是2倍的比率才能显示水晶般清晰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM