简体   繁体   English

仅在添加到主屏幕后,背景图像才不会在iOS上显示

[英]Background images does not display on iOS only after adding to Home Screen

I have a css like this: 我有一个这样的CSS:

#thumbnail {
    background-image: url(bla.jpg),
    background-size: cover,
    background-repeat: no-repeat;
    background-position: 50% 50%;
}

It is showing fine on iOS Safari and everywhere else. 它在iOS Safari和其他任何地方都可以正常显示。 However, when I "Add to Home Screen" the page, the image will not be shown. 但是,当我“添加到主屏幕”页面时,将不会显示图像。

What I tried (with no luck): 我尝试过的(没有运气):

  1. Using background-size: contain 使用background-size: contain

  2. Using JavaScript to "lazy load" the background-image. 使用JavaScript“延迟加载”背景图片。

  3. Dynamically appending it as an <img> instead of a background-image using JavaScript. 使用JavaScript将其动态附加为<img>而不是背景图像。

  4. Adding it straight into HTML document. 直接将其添加到HTML文档中。 It starts displaying but does not obey any CSS style, even after I try it with JavaScript styling, and with width and height attribute (why?). 它开始显示,但是不遵循任何CSS样式,即使我尝试使用JavaScript样式以及widthheight属性(为什么?)也是如此。

  5. Using background-position: top center instead of 50% 50% . 使用background-position: top center而不是50% 50%

  6. Using other image format such as .png . 使用其他图像格式,例如.png

  7. Applying background-image to ::after pseudo-element like below: 将背景图像应用于::after伪元素,如下所示:

     #thumbnail::after { content: ''; display: block; padding-top: 100%; background-image: url(...), background-size: cover, background-repeat: no-repeat; background-position: 50% 50%; } 

It just doesn't work properly. 它只是无法正常工作。

I searched StackOverflow and Google for the same problem, none facing the same issue as most of them are referring to problems in Safari browser and non-supported CSS property (which isn't the problem in my case). 我在StackOverflow和Google上搜索了相同的问题,因为它们都没有遇到相同的问题,因为它们大多数都涉及Safari浏览器中的问题和不受支持的CSS属性(在我看来,这不是问题)。

Does anyone know what could be the problem and how to solve it? 有谁知道可能是什么问题以及如何解决?

This problem only occur after "Add to Home Screen". “添加到主屏幕” 之后才会出现此问题。 It works perfectly fine in iOS Safari browser and iOS Chrome browser. 它可以在iOS Safari浏览器和iOS Chrome浏览器中完美运行。

This might be like a similar issue I had a while ago. 这可能就像我前一段时间遇到的类似问题。

The only workaround we were able to do is to remove the meta tag for it to be "apple-mobile-web-app-capable" and let users to open it in Safari, where everything seems to work normally. 我们唯一能够解决的方法是删除meta标签,使其具有“ apple-mobile-web-app-capable”的功能,并允许用户在Safari中打开它,在Safari中一切正常。

尝试将background-image: url(...)替换为background: url(...)

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

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