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
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>
I think you are missing position: relative
, and a negative value for top
.
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.
You need to use position: absolute;
and the parent must be position: relative
. Without a proper position rule set z-index means squat.