背景尺寸在 Opera Mini 中不起作用,尽管 Modernizr 认为它应该如此
我正在使用 Modernizr 来检测浏览器是否支持我正在构建的移动网站的 CSS3 属性 background-size
。
我正在 Opera 官方网站上的 Opera Mini 6 Simulator 中测试该网站,Modernizr 检测到浏览器支持 background-size
并相应地将“backgroundsize”类添加到 元素中。
但是,当我在 CSS 中使用 background-size
属性时,它不受支持。
这是头部:
<script src="modernizr.js" type="text/javascript"></script>
<style>
body {
background:url('background.gif') no-repeat 0 0 #FFF;
}
.backgroundsize body {
-o-background-size: 100% auto;
background-size: 100% auto;
}
</style>
主体内容
<p>Content</p>
<script>
if (Modernizr.backgroundsize == true) {alert("Background size is supported");}
</script>
我希望单个背景图像能够拉伸到浏览器的整个宽度,而不是重复;该页面可以在这里看到 - http://so.ajcw.com/mobile.htm
我猜猜发生了五件事之一 - 有谁知道原因并可以提供解决方案吗?
- Modernizr 无法正常工作,并给出了误报
- Opera Mini 6 错误地告诉 Modernizr 它支持背景大小,但实际上它不支持
- 模拟器不是准确的模拟,真正的 Opera Mini 确实支持背景大小
- 我错误地编写了代码
- 或者其他什么?
I am using Modernizr to detect whether browsers support the CSS3 property background-size
for a mobile site I'm building.
I'm testing the site in the Opera Mini 6 Simulator on the official Opera website, and Modernizr detects that the browser supports background-size
and adds the class 'backgroundsize' to the <html>
element accordingly.
However when I then use the background-size
property in my CSS it is not supported.
Here's the head:
<script src="modernizr.js" type="text/javascript"></script>
<style>
body {
background:url('background.gif') no-repeat 0 0 #FFF;
}
.backgroundsize body {
-o-background-size: 100% auto;
background-size: 100% auto;
}
</style>
And the body content
<p>Content</p>
<script>
if (Modernizr.backgroundsize == true) {alert("Background size is supported");}
</script>
I am expecting the single background image to be stretched across the full width of the browser, instead it repeats; the page can be seen here - http://so.ajcw.com/mobile.htm
I guess one of five things has happened - does anyone know the reason and can offer a solution?
- Modernizr does not work properly and has given a false positive
- Opera Mini 6 incorrectly tells Modernizr it supports background-size when it doen't
- The simulator is not an accurate emulation and the real Opera Mini does support background-size
- I have written my code incorrectly
- Or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
background-size
Opera Mini 不支持background-size
is not supported in Opera Mini我写这个是为了快速解决问题:
它向 html 元素添加了一个“opera-mini”类。因此您可以瞄准 Opera Mini。以下示例:
查看更多信息:http://anthonydillon.com/blog/#sthash.VUV1hIy2 .dpuf
I wrote this as a quick work around:
It add's a class "opera-mini" to the html element. Therefore you can target Opera Mini. An example below:
See more at: http://anthonydillon.com/blog/#sthash.VUV1hIy2.dpuf
看来事情已经改变了。适用于我的 Android 版 Opera Mini 7.5。
它可以正确响应百分比值以及
cover
和contain
。It seems things have changed. For my Opera Mini 7.5 on Android.
And it responds correctly to percentage values as well as to
cover
andcontain
.@anthony 的答案不起作用,因为它没有重置/删除 Opera Mini 的背景大小属性。正确的方法是:
x:-o-prefocus 仅针对 Opera 浏览器。
@anthony's answer doesn't work as it's not resetting / removing the background-size property for Opera Mini. The correct way to do this is:
The x:-o-prefocus targets just Opera browsers.