html - 如何在 bootstrap 表格单元格中显示重叠的图片?

标签 html css twitter-bootstrap

我无法在 Bootstrap 表中成功显示重叠的图片。

这个想法当然是将几个相似的图标很好地分布在一条线上。

代码是:

<style type="text/css">
.under
{
    position:absolute;
    left:17px;
    top:4px;
    z-index:-1;
}
.over
{
    position:absolute;
    left:16px;
    top:4px;
    z-index:-1;
}

</style>

<table class="table table-bordered">
    <tbody>
        <tr>
            <td>
                <img class="under" height="41" alt="Drinks" src="//i.imgur.com/S8t8vOy.png"></img>
                <img class="over" height="43" alt="Drinks" src="//i.imgur.com/zrC8Mxy.png"></img>
            </td>
        </tr>
    </tbody>
</table>

这是我的 fiddle http://jsfiddle.net/c8zn41b3/

有什么想法吗?

最佳答案

为了能够获得您想要的效果,您不能绝对定位这两个元素。绝对位置将元素带离 dom,除非它有一个相对位置的父容器。因此,您需要的是让 img 的父级相对定位以包含绝对位置,然后相对于其中一个 img 定位,因为您不会得到缩小表。然后将另一个 img 定位为绝对位置。

DEMO

CSS

td {
    position: relative;
}
.under {
    position:relative;
    left:17px;
    top:4px;
    z-index:-1;
}
.over {
    position:absolute;
    left:22px;
    top:4px;
    z-index:-1;
}

关于html - 如何在 bootstrap 表格单元格中显示重叠的图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29240370/

相关文章:

javascript - 重新加载 Bootstrap 表刷新并更改设置

html - 9 张图像在 HTML 和 CSS 中缩小到 3x3 网格中?

css - 如何测试CSS方向: auto as an english speaker

html - 如何修复最大宽度和 float :left interaction

javascript - jQuery:添加到 DOM 的新图像在加载后始终具有宽度 0

Javascript:单击 div/form 中的按钮不执行针对它的 javascript?

html - Bootstrap CSS 行的高度变化导致以下所有内容的跳跃和可用性问题

CSS背景图片挣扎

html - 右侧固定宽度div,左侧填充剩余宽度div

jquery - Twitter 关闭时 Bootstrap 模式动画