问题 在CSS中重叠图像


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

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>

1000
2017-10-24 21:47


起源



答案:


#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;
} 

12
2017-10-24 21:55



工作得很完美!非常感谢! - MP123
不用担心哥们,随时都可以。希望你明白那里发生了什么:) - Claudiu
background-size:80px ??px; 可用于指定图像的大小。 - Anirudh


答案:


#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;
} 

12
2017-10-24 21:55



工作得很完美!非常感谢! - MP123
不用担心哥们,随时都可以。希望你明白那里发生了什么:) - Claudiu
background-size:80px ??px; 可用于指定图像的大小。 - Anirudh


尝试

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

2
2017-10-24 21:51



在我的情况下,z-index是重要的参数。谢谢 ! - Aamol


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

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

然后添加边距(和位置:绝对)以将图像定位在所需位置。


0
2017-10-24 21:56