简体   繁体   中英

How to get a table to overlap an image?

Here is a small snippet of my HTML:

<img src="http://hss.fullerton.edu/philosophy/Red%20Square.gif" id="test1" />
<table id="test2">
    <tr><td>Test</td></tr>
</table>

I have an image of a red square and I want the table to overlap the bottom of it. Here is the CSS:

#test1 {
    width: 42px;
    height: 42px;
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: -15px;
}

#test2 {
    z-index: 1;
    background-color: pink;
    width: 80px;
    height: 50px;
    margin-left: auto;
    margin-right: auto;
}

It isn't working, however:

在此输入图像描述

As you can see, the image is still on top of the table - not what I want. Notice in my CSS that I've explicitly set the table's z-index to 1 and it still won't overlap the image. What am I doing wrong?

jsFiddle: http://jsfiddle.net/george_edison/uk7Pz/

Try positioning each element. Add position:relative to each element, as demonstrated here: http://jsfiddle.net/8nGKk/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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