简体   繁体   English

Android 2.3上奇怪的Z-index行为

[英]Weird z-index behaviour on Android 2.3

I think I may have come across another z-index bug in Android 2.3. 我想我可能在Android 2.3中遇到了另一个Z-index错误。 We have this widget, which renders like this on all major OS/browser combos: 我们有这个小部件,它在所有主要的OS /浏览器组合上都呈现为:

在此处输入图片说明

Here's the HTML we're using: 这是我们正在使用的HTML:

<ol>
    <li>
        <span class="ranking">1</span>
        <h3>
            <a href="...">TT Legends shows the exhilaration of motorbike racing</a>
        </h3>
        <span class="score-bar" style="width: 610px;"></span>
    </li>
    <li>
        <span class="ranking">2</span>
        <h3>
            <a href="...">101-year-old grandmother 'comes back from the dead'</a>
        </h3><span class="score-bar" style="width: 421px;"></span>
    </li>
</ol>

and this is the CSS: 这是CSS:

.trending ol {
    counter-reset: item;
    list-style-type: none;
    overflow: hidden;
}

.trending li {
    position: relative;
    min-height: 42px;
    margin-bottom: 10px;
    overflow: hidden;
}

.trending .ranking {
    display: table-cell;
    vertical-align: middle;
    min-width: 40px;
    text-align: center;
}

.trending h3 {
    display: table-cell;
    vertical-align: middle;
    position: relative;
    z-index: 2;
    width: 100%;
    margin-left: 40px;
    padding: 5px;
    line-height: 1.2;
}

.score-bar {
    display: inline-block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 40px;
    width: 0;
    z-index: 0;
    background: #f3f5f9;
}

We use JS to set the width of the blue .score-bar span according to the score of the item concerned. 我们使用JS根据相关项目的得分设置蓝色.score-bar跨度的宽度。

On Android 2.3 devices like the HTC Desire and Samsung Galaxy S2 it ends up like this: 在HTC Desire和Samsung Galaxy S2等Android 2.3设备上,其最终结果如下:

在此处输入图片说明

Can anyone suggest a solution? 谁能提出解决方案? I've tried all the CSS tweaks I can think of, but nothing seems to fix it. 我已经尝试了所有可以想到的CSS调整,但是似乎没有任何解决办法。

What you need to do is move the .score-bar background styling to something other than the span. 您需要做的是将.score-bar背景样式移动到跨度以外的其他样式。

Delete the score-bar spans, and use the following instead. 删除分数栏范围,然后使用以下内容。

Here is the jsfiddle example... http://jsfiddle.net/qaYbS/ 这是jsfiddle示例... http://jsfiddle.net/qaYbS/

NOTE: In jsfiddle I used background color, for your instance you will need to use an actual image. 注意:在jsfiddle中,我使用了背景色,对于您的实例,您将需要使用实际图像。 Just make an image that is the height you need and 1px wide and use that. 只需制作一个图像即可,即您所需的高度和1px的宽度,然后使用它。 It won't increase load times at all. 它根本不会增加加载时间。 This is the only way to get the width of the background to shrink accordingly. 这是使背景宽度相应缩小的唯一方法。 You can constrain the size of a background color. 您可以限制背景颜色的大小。

.trending li:nth-child(1) {
    background: red;
    background-image: ;
    background-size: 610px 20px;
    background-position: 40px 0px;
}
.trending li:nth-child(2) {
    background: blue;
    background-image: ;
    background-size: 421px 20px;
    background-position: 40px 0px;
}
.trending li:nth-child(3) {
    background: green;
    background-image: ;
    background-size: 300px 20px;
    background-position: 40px 0px;
}
.trending li:nth-child(4) {
    background: orange;
    background-image: ;
    background-size: 200px 20px;
    background-position: 40px 0px;
}
.trending li:nth-child(5) {
    background: purple;
    background-image: ;
    background-size: 100px 20px;
    background-position: 40px 0px;
}

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

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