css - z-index 的背景图像不完全透明

标签 css

我正在用 dart 编写一个坦克游戏。它是 27 * 27 的表。对于每个字段,我都使用 background-image 属性。例如我的坦克由 4 个小区域组成。 Tank 在光栅上只占用 1 个小字段。但是通过伪类 .bg-player-left:before 如果实现的话,那个坦克看起来像 4 野战坦克。与子弹相同的想法。它在光栅上只需要一个字段,但看起来像 2。问题是,这个对象的左上角位置总是黑色的。

enter image description here

        .bg-water {
        background-image: url("../img/water-field.png");
        background-size: cover;
        background-repeat: no-repeat;
    }

    .bg-bush {
        background-image: url("../img/bush-field.png");
        background-size: cover;
        background-repeat: no-repeat;
        opacity: 0.8;
    }
.bg-bullet-up, .bg-bullet-down, .bg-bullet-left, .bg-bullet-right,
.bg-player-up, .bg-player-down, .bg-player-left, .bg-player-right {
    position: relative;
}

.bg-player-up:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0px;
    right: -15px;
    bottom: -15px;
    background-image: url("../img/player-tank-left.png");
    background-size: contain;
    background-repeat: no-repeat;
    z-index: 1;
}

.bg-bullet-up:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0px;
    right: -15px;
    bottom: -15px;
    background-image: url("../img/bullet-left.png");
    background-size: contain;
    background-repeat: no-repeat;
    z-index: 1;
}

你也可以自己试试(https://javajunikorn.github.io/BattleCity/build/web/html/test.html) 为了移动坦克,您需要从移动设备或移动版本的浏览器检查器中启动游戏。

最佳答案

用伪类变形对象的有趣想法。

可能是因为您将 css 颜色背景设置为黑色,在子弹和坦克的 png 上造成了这种失真? 如果我去这里:https://javajunikorn.github.io/BattleCity/build/web/img/bullet-left.png

我可以在 css 中看到这个属性:

背景:#0e0e0e;

关于css - z-index 的背景图像不完全透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50793227/

相关文章:

基于内容的 CSS 规则

javascript - 使用 javascript 或 jquery 对 html 图像或按钮的实时平铺倾斜效果?

html - CSS : different placements for img with caption

css - 将 Bootstrap 选择器字段的标题右对齐

javascript - Jquery FadeIn FadeOut不断重复

html - No-Children-But-Not-Empty 的 CSS 选择器

html - 悬停功能仅适用于悬停元素的更改

javascript - 显示边框的 JQuery 生日选择器

html - 为什么我的元素没有以正确的方式 float ?

javascript - 悬停时的 jQuery 背景渐变