背景尺寸在 Opera Mini 中不起作用,尽管 Modernizr 认为它应该如此

发布于 2024-12-09 12:13:50 字数 1234 浏览 1 评论 0原文

我正在使用 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

我猜猜发生了五件事之一 - 有谁知道原因并可以提供解决方案吗?

  1. Modernizr 无法正常工作,并给出了误报
  2. Opera Mini 6 错误地告诉 Modernizr 它支持背景大小,但实际上它不支持
  3. 模拟器不是准确的模拟,真正的 Opera Mini 确实支持背景大小
  4. 我错误地编写了代码
  5. 或者其他什么?

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?

  1. Modernizr does not work properly and has given a false positive
  2. Opera Mini 6 incorrectly tells Modernizr it supports background-size when it doen't
  3. The simulator is not an accurate emulation and the real Opera Mini does support background-size
  4. I have written my code incorrectly
  5. Or something else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

_蜘蛛 2024-12-16 12:13:50

background-size Opera Mini 不支持

background-size is not supported in Opera Mini

听,心雨的声音 2024-12-16 12:13:50

我写这个是为了快速解决问题:

var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
if(isOperaMini) {
    var root = document.documentElement;
    root.className += " opera-mini";
}

它向 html 元素添加了一个“opera-mini”类。因此您可以瞄准 Opera Mini。以下示例:

.icon {
    background-image: url("icon-social.svg");
    background-size: 32px;
}

html.opera-mini .icon,
html.no-svg .icon {
    background-image: url("icon-social.png");
}

查看更多信息:http://anthonydillon.com/blog/#sthash.VUV1hIy2 .dpuf

I wrote this as a quick work around:

var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
if(isOperaMini) {
    var root = document.documentElement;
    root.className += " opera-mini";
}

It add's a class "opera-mini" to the html element. Therefore you can target Opera Mini. An example below:

.icon {
    background-image: url("icon-social.svg");
    background-size: 32px;
}

html.opera-mini .icon,
html.no-svg .icon {
    background-image: url("icon-social.png");
}

See more at: http://anthonydillon.com/blog/#sthash.VUV1hIy2.dpuf

鹤仙姿 2024-12-16 12:13:50

看来事情已经改变了。适用于我的 Android 版 Opera Mini 7.5。

Modernizr.backgroundsize == true;

它可以正确响应百分比值以及covercontain

It seems things have changed. For my Opera Mini 7.5 on Android.

Modernizr.backgroundsize == true;

And it responds correctly to percentage values as well as to cover and contain.

枕梦 2024-12-16 12:13:50

@anthony 的答案不起作用,因为它没有重置/删除 Opera Mini 的背景大小属性。正确的方法是:

.class {
  -o-background-size:cover;
  -background-size:cover;
}
x:-o-prefocus, .class {
  -o-background-size:;
  background-size:;
}

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:

.class {
  -o-background-size:cover;
  -background-size:cover;
}
x:-o-prefocus, .class {
  -o-background-size:;
  background-size:;
}

The x:-o-prefocus targets just Opera browsers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文