简体   繁体   English

iPhone / iPad背景图片上的错误元素

[英]iPhone/iPad background image on wrong element

I have an issue where, ocassionally, when I set a background image on an HTML element it displays a completely random image that is also set as a background image elsewhere on the page. 我有一个问题,即当我在HTML元素上设置背景图像时,它会显示一个完全随机的图像,该图像也被设置为页面上其他位置的背景图像。

For example, I have a list item that has a background image "myimage-abc.jpg". 例如,我有一个列表项,其背景图像为“ myimage-abc.jpg”。 I also have a div with a background image of "myimage-123.jpg". 我也有一个div,背景图片为“ myimage-123.jpg”。 Everything is as expected for most people however for some Apple users (of which my Managing Director is one) the image "myimage-123.jpg" shows up on the list item as well as the div. 一切对大多数人来说都是预期的,但是对于某些Apple用户(我的董事总经理是其中的一个),图像“ myimage-123.jpg”显示在列表项以及div上。

Has anyone else had this issue before? 以前有人遇到过这个问题吗? Any ideas how to get around it? 任何想法如何解决它?

Thanks 谢谢

Use inspect element on the element with incorrect background image and see which CSS selectors are overriding the background image that you want to have. 在背景图片不正确的元素上使用inspect元素,查看哪些CSS选择器将覆盖您想要的背景图片。

Then report back with the CSS selectors responsible for styling the elements in here. 然后在这里报告负责样式设置的CSS选择器。 Keep in mind that CSS selectors are very particular about the way in which you use them. 请记住,CSS选择器在使用它们的方式上非常特别。

Until then here's something that could be causing your problem, without my knowing your current CSS state. 在此之前,这里可能会导致您的问题,而我不知道您当前的CSS状态。

From an answer on another question : 从另一个问题的答案:

I've dealt with this before and it's always a strange issue. 我之前已经处理过,这始终是一个奇怪的问题。 So here are some thoughts and examples of CSS behavior. 因此,这里有一些CSS行为的想法和示例。

In CSS we have a hierarchy decided both on how you select an element and on its position within your stylesheet. 在CSS中,我们有一个层次结构来决定如何选择元素以及元素在样式表中的位置。 Take for example the following CSS selectors: 以以下CSS选择器为例:

body .test-parent .test-child {
    color: red;
}
body .test-parent .test-child {
    color: blue;
}

The result in this case would return color: blue; 在这种情况下,结果将返回color: blue; as the final style as it is the last read declaration for that elements color value. 作为最终样式,因为它是该元素颜色值的最后读取声明。

However if we declare the following: 但是,如果我们声明以下内容:

body .test-parent-two .test-child-two {
    color: red;
}
body .test-child-two {
    color: blue;
}

Then the final value is color: red; 然后,最终值为color: red; . This caught me off guard and it took me a while to notice the pattern and fix. 这让我措手不及,花了我一段时间才注意到模式并修复。

The problem here lies in the selectors. 这里的问题出在选择器上。 A more in-depth selector (longer / includes more in-between children) will override any others as can be seen by this JSFiddle . JSFiddle可以看到,更深入的选择器(更长/包括更多的中间子元素 )将覆盖任何其他选择器。

Hope that also helps! 希望对您有所帮助!

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

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