简体   繁体   English

CSS背景图像在iPhone上呈现不同

[英]CSS background image rendering differently on iPhone

We have a page design that works great in every PC browser that I have tried, but goes strange when viewed with an iPhone or iPod Touch. 我们的页面设计在我尝试过的每个PC浏览器中都很有效,但在使用iPhone或iPod Touch查看时却很奇怪。

The problem is something to do with a centred background image thats very tall: 问题与中心背景图像有很大关系:

#content_container
{

background-image:url('content-background.jpg');
background-position:top center;
background-repeat:no-repeat;
width:1020px;
height:auto;
}

The content-background.jpg image is very tall (3000 pixels) and is designed to be 'revealed' as the DIV it is in grows due to content. content-background.jpg图像非常高(3000像素),并且由于内容的原因而被设计为“透露”它正在增长的DIV。

You'll have to look at the page and full CSS to understand, so I've stripped everything else out of the design and re-produced the problem with this example: 你必须看一下页面和完整的CSS来理解,所以我已经从设计中剥离了所有其他东西,并用这个例子重新产生了问题:

http://files.codeulike.com/static/cssexample/example.htm http://files.codeulike.com/static/cssexample/example.htm
(example made up of 1 html file, 1 css file and 3 images) (例子由1个html文件,1个css文件和3个图像组成)

You'll see that in IE8, Firefox, Chrome you'll get a nice green box. 你会看到在IE8,Firefox,Chrome中你会得到一个漂亮的绿色框。 But in an iOS browser the long thin background image gets re-scaled and everything goes odd. 但是在iOS浏览器中,长薄的背景图像会被重新缩放,一切都变得奇怪。

(I'm using an iPod Touch 2nd gen but I assume the same problem will happen in other iPhones/iPod touches). (我正在使用iPod Touch第二代,但我认为在其他iPhone / iPod touch中会出现同样的问题)。

Any help greatly appreciated! 任何帮助非常感谢!

Figured it out: The iPhone has a megapixel limit for Jpegs, after which it shrinks the Jpeg. 弄清楚:iPhone对Jpegs有百万像素的限制,之后它缩小了Jpeg。

There's a very good blog post about this on defusion.org.uk: http://www.defusion.org.uk/archives/2010/02/19/shrinking-large-background-image-bug-in-iphone-safari/ 在defusion.org.uk上有关于此的非常好的博客文章: http//www.defusion.org.uk/archives/2010/02/19/shrinking-large-background-image-bug-in-iphone-safari /

The limit after which Jpegs get shrunk seems to be around 2 megapixels. Jpegs缩小之后的限制似乎是大约2百万像素。 Its a documented iOS resource limit and is described here: 它是一个记录的iOS资源限制,在此处描述:

Apple - Creating Compatible Web Content - Know iOS Resource Limits Apple - 创建兼容的Web内容 - 了解iOS资源限制

The maximum decoded image size for JPEG is 32 megapixels using subsampling. 使用子采样,JPEG的最大解码图像尺寸为3200万像素。

JPEG images can be up to 32 megapixels due to subsampling, which allows JPEG images to decode to a size that has one sixteenth the number of pixels. 由于子采样,JPEG图像可以达到3200万像素,这使得JPEG图像可以解码为像素数量的十六分之一。 JPEG images larger than 2 megapixels are subsampled—that is, decoded to a reduced size. 大于2百万像素的JPEG图像被二次采样 - 即,解码为缩小的尺寸。 JPEG subsampling allows the user to view images from the latest digital cameras. JPEG子采样允许用户查看来自最新数码相机的图像。

.. which I take to mean that Jpegs under 2 megapixels are displayed normally, Jpegs between 2 and 32 megapixels are displayed by subsampling (shrinking), and Jpegs over 32 megapixels presumably can't be displayed at all. ..我认为正常显示2百万像素以下的Jpegs,通过二次采样(收缩)显示2到32百万像素之间的Jpegs,并且可能根本无法显示超过32百万像素的Jpegs。

Changing my site to use a background image that was under 2 megapixels solved the problem. 更改我的网站以使用低于2百万像素的背景图像解决了这个问题。

I realize this post is two years old as I write this, but I tried something that worked, perhaps not the best way to go but it solved my problem. 当我写这篇文章时,我意识到这篇文章已有两年了,但我尝试了一些有用的东西,也许不是最好的方法,但它解决了我的问题。

First step was to save my background image as a .png which cured the problem completely...except being a 1200px x 12000px background image, the .png file was a monster. 第一步是将我的背景图像保存为完全解决问题的.png ...除了是一个1200px x 12000px的背景图像,.png文件是一个怪物。

So, I opened the .png file in Photoshop and saved it optimized for web and devices as a .jpg and uploaded that file and it worked like a charm on the iPhone and all of the big 5 browsers. 所以,我在Photoshop中打开了.png文件并将其保存为优化的网页和设备作为.jpg并上传该文件,它就像iPhone上的魅力和所有五大浏览器一样。

Hope that helps! 希望有所帮助!

不太正确,我有一个背景1640x1200(sub 2Mpix),背景缩小......:S

If you have kept 如果你保留了

background-attachment: fixed;

in desktop CSS file, then remember it to change it to 在桌面CSS文件中,然后记住它将其更改为

background-attachment: scroll;

in mobile CSS file. 在移动CSS文件中。 If this is not done that it will show unexpected effect. 如果没有这样做,它将显示意想不到的效果。

我使用了Safaris CSS3多个背景图像来解决这个问题,只做了4张高500像素的图像并将它们放在彼此的顶部

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

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