html - 将 div 置于图像之上

标签 html css

我想将一个包含 addsense 脚本内容的 DIV 放在我用作横幅的 img 之上。

我在 div 中有 img 标签。然后我将谷歌脚本放在下面的 div 中并为其设置此样式

style="float:right;left:250;z-index:2"

添加显示在 img 下方,而不是其上方。有什么想法吗??

最佳答案

你想用 absolute 定位第二个 div:

http://jsfiddle.net/sbNZu/

相关代码:

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>

关于html - 将 div 置于图像之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4218204/

相关文章:

php - 检查数据库列中是否存在部分字符串

php - 我想制作一个下拉菜单,点击后列表将打开,而不是使用 CSS 鼠标悬停,而不是使用 jquery、javascript 等

javascript - 滚动到 uRL 中具有多个 anchor 的 anchor ,

css - 在溢出的 div 中滚动背景

css - 没有样式表正在工作期望 wordpress 中的菜单

javascript - webpack构建后如何保留所有功能?

html - 选择每 4 个 <div>

javascript - JS/CSS : backgroundColor for second class

html - 为什么容器 div 不包裹子 div(溢出容器)

html - float 未被清除