html - 如何将图像放置在图像上?

标签 html css

我正在为响应式网站工作。我想将小图像放在大图像上。小图像应放置在大图像的正中心。我无法将大图像作为页面背景。它应该在div内部。怎么办?

JSFIDDLE

//code
<div class="text-center">
    <img id="draggable1" class="img-responsive" src="http://photos.foter.com/a266/freestanding-wood-and-wire-pet-gate-size-21-width-narrow-span-2658163_300x300.jpg">
       <img class="heartimg" src="http://gorgeousme.co/media/19340/heart_50x42.jpg"/>
    </img>
</div>

最佳答案

在心脏img上使用绝对定位

JSFiddle Demo

CSS

.text-center {
    display: inline-block;
    border:1px solid grey;
    position: relative;
}

.text-center img {
    display: block;
}

.text-center .heartimg {
    position: absolute;
    top:50%;
    left:50%;
    margin-top:-25px; /* half of it's height */
    margin-left:-21px; /* half of it's width */
}

关于html - 如何将图像放置在图像上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22069563/

相关文章:

javascript - jQuery 应用 :nth-child(#) and addClass() to div, 不会向元素添加类

Jquery css 代码在浏览器中不起作用

jquery - 我可以以编程方式关闭可折叠导航栏显示的下拉菜单吗?

html - 当用户放大或缩小时,避免破坏设计网页

添加样式时 jquery 选择器失败(多个 css 类)

jquery - jssor slider 问题 - 最小化低于 1200px 的窗口时添加滚动

html - 如何防止菜单项之间出现间隙?

javascript - 使滚动侧边栏停在页脚处

html - 搜索框内的搜索图标

Python - 输入标签内正则表达式中的转义引号