CSS CSS中的重叠图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4010624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:01:30  来源:igfitidea点击:

Overlap images in CSS

css

提问by MP123

How do I get "mymessage.gif" to show over "bread_wine.jpg".

如何让“mymessage.gif”显示在“bread_wine.jpg”上。

mymessage.gif has a transparent background.

mymessage.gif 具有透明背景。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>overlap images</title>
<style type="text/css">
<!--
#navbar {
    font-size: 18px;
    font-weight: bold;
    text-align: center; 
}
#thebigimage {
    background-image: url(bread_wine.jpg);
    height: 548px;
    width: 731px;
    margin-right: auto;
    margin-left: auto;
}
#overlapthis {
    background-image: url(mymessage.gif);
}
-->
</style>
</head>
<body>
<div id="navbar">this is the nav bar</div>
<div id="thebigimage">
<div id="overlapthis"></div>
</div>
</body>
</html>

采纳答案by Claudiu

#overlapthis {
    background-image:url("mymessage.gif");
    height:100px;
    left:50px; /* play around with this */
    position:absolute;
    top:90px; /* and play around with this */
    width:500px;
}

#thebigimage {
    background-image:url("bread_wine.jpg");
    height:548px;
    margin-left:auto;
    margin-right:auto;
    position:relative; /* and this has to be relative */
    width:731px;
} 

回答by Jakub Konecki

Try

尝试

#overlapthis {
    position: absolute;
    top: ??px;
    left: ??px;
    z-index: 1;
}

回答by Kablam

As you have it right now, the image overlaps already. You just can't see it because you didn't add sizes to your overlapthis div. Try this:

正如您现在拥有的那样,图像已经重叠。你只是看不到它,因为你没有给你的overlapthis div 添加尺寸。尝试这个:

#overlapthis {
    background-image: url(mymessage.gif);
    width: 500px;
    height: 100px;
}

Then add margins (and an position: absolute) to position the image at your desired location.

然后添加边距(和位置:绝对)以将图像定位在您想要的位置。