简体   繁体   English

CSS - 另一个图像上的图像,均居中

[英]CSS - image over another image , both centered

I have two images, one on another.我有两张图片,一张一张。 like this:像这样:

在此处输入图片说明

But, when the screen resize, the "play image" is not centered (like this:但是,当屏幕调整大小时,“播放图像”不会居中(如下所示: 在此处输入图片说明

This is my html:这是我的 html:

<div class="flapImage" id="idHot">                        
     <img src="images/hot.png" style="position:relative; top:0; left:0; max-width:390px;" width="100%" height="190px" />
     <img src="images/watchVideoP.png" width="200px" style="position:absolute; top:120px; left:80px;" />
</div>

And this is my css:这是我的 css:

.flapImage{
   margin:0 auto;
   text-align:center;
   top:0;
   left:0;
   background-color:black;
}

You know another way to do it?你知道另一种方法吗?

Add this property添加此属性

<div class="flapImage" id="idHot">                        
     <img src="images/hot.png" style="position:relative; top:0; left:0; max-width:390px;" width="100%" height="190px" />
     <img src="images/watchVideoP.png" width="200px" style="position:absolute; top:50%; left: 50%; transform: translate(-50%, -50%);" />
</div>

use absolute and relative positioning, make the main image relative and other absolute.使用绝对和相对定位,使主图像相对和其他绝对。 then write this in hovered image clas :然后在悬停的图像类中写下这个:

left: 50%;
top: 50%;
transform: translate(-50%, -50%)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM