如何在上放置/覆盖透明 *png使用CSS?

发布于 2024-11-19 15:59:19 字数 852 浏览 4 评论 0原文

问题

我需要在表格元素上放置一个透明的 png 图像。

澄清

我所说的“放置”是指图像将像层或贴纸一样堆叠在桌子顶部,而不是垂直位于其上方。换句话说,我希望图像在 z 轴上向前移动,而不是在 y 轴上向上移动。

上下文

我有 8 x 6 单元格表。单元格不包含文本,但包含背景颜色以暗示值。出于美观原因,我想在桌子上放置一个白色轮廓设计。

我尝试过

将表格包装在 div 中,将图像应用为背景,然后尝试将其在 z 索引上向前移动。

HTML 基本演示:

<div class="table-foreground">
    <table>
        <tr>
            <td>
            </td>
        </tr>
    </table>
</div>

随附 CSS 基本演示:

td{
background-color:#000;
}

div.table-foreground{
background-image:url(images/table-foreground.png);
position:relative;
z-index:5;
}

结果

注意:科学家要求我提供尝试代码的结果.

从视觉上看,什么也没有发生。我推测以 png 图像为背景的 div 位于我的桌子下方。这表明我的代码还不够。

The problem

I need to place a transparent png image over a table element.

Clarification

By "place" I mean the image will be stacked on top of table like a layer or sticker rather than vertically above it. In other words, I want my image to move forward on the z axis rather than moving upward on the y axis.

Context

I have 8 x 6 cell table. The cells do not contain text but do contain a background color to imply a value. I want to place a white silhouetted design over the table for aesthetic reasons.

What I've tried

I've tried wrapping the table in a div, applying the image as a background and then tried bringing it forward on the z-index.

Basic demonstration of HTML:

<div class="table-foreground">
    <table>
        <tr>
            <td>
            </td>
        </tr>
    </table>
</div>

Basic demonstration of accompanying CSS:

td{
background-color:#000;
}

div.table-foreground{
background-image:url(images/table-foreground.png);
position:relative;
z-index:5;
}

The result

Note: thescientist requested that I provide the result of my attempted code.

Visually, nothing happens. I speculate that the div with the png image as it's background is beneath my table. This suggests that my code is not sufficient.

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

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

发布评论

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

评论(1

木森分化 2024-11-26 15:59:19
  1. 将表格包裹在 div 中(位置:相对;)
  2. 将表格放在里面
  3. 将图像放入 div 中(位置:绝对;顶部:Y;左侧:X;)
  4. 更改 X 和 Y,直到它位于表格上方您想要的位置。

<div style="position: relative;">
    <table>

    </table>
    <div style="background-image: url('picURL'); position: absolute; top: Y; left: X; width:Xpx;height;Ypx;">
    </div>
</div>
  1. wrap your table in a div (position: relative;)
  2. put your table inside
  3. put your image inside the div (position: absolute; top: Y; left: X;)
  4. change X and Y until it's where you want it over the table.

<div style="position: relative;">
    <table>

    </table>
    <div style="background-image: url('picURL'); position: absolute; top: Y; left: X; width:Xpx;height;Ypx;">
    </div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文