Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在图像上放置图像?_Jquery_Css - Fatal编程技术网

Jquery 如何在图像上放置图像?

Jquery 如何在图像上放置图像?,jquery,css,Jquery,Css,假设我有一个div,div有img标签,比如 因此,当页面运行时,img1.png将加载到div中。我只需要知道如何将另一个小图像放置在页面中心,就像img1.png上的任何繁忙图像一样。使用jquery或css的最佳方式是什么。给我css或jquery,用于将小图像放置在中心的div上 我还有一个问题,如果一个div使用css设置了背景图像,那么我可以确定背景图像下载完成了还是没有使用jquery?如果可能的话,请给我一个示例代码。谢谢将第一张图像作为div的背景: <div style

假设我有一个div,div有img标签,比如
因此,当页面运行时,img1.png将加载到div中。我只需要知道如何将另一个小图像放置在页面中心,就像img1.png上的任何繁忙图像一样。使用jquery或css的最佳方式是什么。给我css或jquery,用于将小图像放置在中心的div上


我还有一个问题,如果一个div使用css设置了背景图像,那么我可以确定背景图像下载完成了还是没有使用jquery?如果可能的话,请给我一个示例代码。谢谢

将第一张图像作为div的背景:

<div style="background: url('img1.png')">
 <img src="img2.png" style="margin 0 auto" />
</div>


这将使第二个图像居中(仅在水平方向上,但在垂直方向上)。您可能需要稍微修改
margin
top
属性(如果使用
absolute
relative
定位)。但是,如果它只是另一个图像中的一个图像,您可以稍微摆弄一下页边顶部,它应该可以做到这一点。

使用wrap在图像顶部添加另一个div

$("#divID img").each(function() {
    var $overlay = $('<div></div>');
    $overlay.css({
        position: "relative",
        display: "inline-block",
        width: $(this).width(),
        height: $(this).height(),
        backgroundPosition: "center center",
        backgroundImage: "url(loading-image.gif)"
    });
    $(this).wrap($overlay);
});
$(“#divID img”)。每个(函数(){
变量$overlay=$('');
$overlay.css({
职位:“相对”,
显示:“内联块”,
宽度:$(this).width(),
高度:$(this).height(),
背景位置:“中心”,
背景图像:“url(正在加载image.gif)”
});
$(this.wrap($overlay);
});
要放置图像,必须是目标元素的子元素。。。
请尝试并回复。

CSS3支持多个背景层


你有什么代码可以看吗?检查CSS z-index属性,让元素一个接一个地堆叠起来。你已经试过什么了?这不是你来找别人帮你写代码的地方。。。你甚至用谷歌搜索过你的问题吗?如何放置另一个div不仅在图像的顶部,而且我需要将div放置在图像的中心…这将如何实现?将覆盖图像的宽度和高度设置为图像的宽度和高度,然后使用背景位置将背景图像置于div的中心。唯一的问题是这需要图像的宽度和高度才能工作。
$("#imageToPlaceDivID").position({
  my: "center center",
  at: "center center",
  of: "#IDOfTargetElementWhereYouWantToPlace"
});
#example1 {
  width: 500px;
  height: 250px;
  background-image: url(sheep.png), url(betweengrassandsky.png);
  background-position: center bottom, left top;
  background-repeat: no-repeat;
}