position a div on top of an image

后端 未结 4 1033
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 05:50

I want position a DIV with the content of an addsense script on top of a img that I use as a banner.

I have the img tag inside a div. then I put the google script inside

相关标签:
4条回答
  • 2021-02-04 06:02

    You want to position the second div with absolute:

    http://jsfiddle.net/sbNZu/

    Relevant code:

    img {
        border: 2px solid black;   
    }
    
    #container {
        position: relative;    
    }
    
    #example {
       position: absolute;
       top: 10px;
       left: 10px; 
        
       padding: 5px;
       background-color: white;
       border: 2px solid red;
    }
    <div id="container">
        <img src="https://placekitten.com/g/193/129">
        <div id="example">This is my div</div>
    </div>

    0 讨论(0)
  • 2021-02-04 06:05

    I think you are missing position: relative, and a negative value for top.

    0 讨论(0)
  • 2021-02-04 06:08

    Have the parent with position: relative, the children with position: absolute, and use negative values for margin on the children to move it on top. You may not even need to deal with z-index.

    0 讨论(0)
  • 2021-02-04 06:16

    You need to use position: absolute; and the parent must be position: relative. Without a proper position rule set z-index means squat.

    0 讨论(0)
提交回复
热议问题