android - Android 2.3 上奇怪的 z-index 行为

标签 android html css samsung-mobile

我想我可能遇到过 Android 2.3 中的另一个 z-index 错误。我们有这个小部件,它在所有主要操作系统/浏览器组合上都像这样呈现:

enter image description here

这是我们使用的 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>

这是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;
}

我们使用JS根据关注项的得分设置蓝色.score-bar span的宽度。

在像 HTC Desire 和 Samsung Galaxy S2 这样的 Android 2.3 设备上,它最终是这样的:

enter image description here

谁能提出解决方案?我已经尝试了所有我能想到的 CSS 调整,但似乎无法解决问题。

最佳答案

您需要做的是将 .score-bar 背景样式移动到 span 之外的其他样式。

删除得分栏跨度,并改用以下内容。

这是 jsfiddle 示例... http://jsfiddle.net/qaYbS/

注意: 在 jsfiddle 中,我使用了背景色,对于您的实例,您需要使用实际图像。只需制作一个您需要的高度和 1 像素宽的图像并使用它。它根本不会增加加载时间。这是使背景宽度相应缩小的唯一方法。您可以限制背景颜色的大小。

.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;
}

关于android - Android 2.3 上奇怪的 z-index 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14648856/

相关文章:

css - 粘性页眉和页脚

android - 使用 Appium 推送通知自动化

html - 如何在 bootstrap 4 中使下拉菜单的宽度等于其父级的宽度

php - PHP 重定向后图像不刷新(缓存问题?)

javascript - 我的网站的 Java 表单验证

javascript - 具有 HTML 格式的 AngularJS 动态行生成

java - 在给定文件名的图库应用程序中显示照片

java - Android/PHP/MySQL 项目协助 - 保持服务器和手机应用程序同步

android - 如何交换在两个文本框中输入的文本?

html - @font-face 不工作 - 相同的代码但不同的主机