简体   繁体   English

如何在不移动其他图片的情况下将图片悬停在其他图片上?

[英]How to make a picture hover over others without moving the other pictures?

Originally, in my CSS, I have 4 images set together. 最初,在CSS中,我设置了4张图像。 2 are on top, floated next to each other, and 2 are on the bottom. 2个在顶部,彼此相邻漂浮,2个在底部。

.img1 {
    float: left;
}

.img2 {
    float: left;
}

.clear1 {
    clear: both;
}

.img3 {float: left;}
.img4 {float: left;}
.clear {clear: both;}

This is the basic idea of the code that I have for the 4 images to be next to each other, 2 on top, and 2 on the bottom. 这是我将4张图像彼此相邻,顶部2个,底部2个的代码的基本思想。 I want the first image, when I hover over it, to cover the other 3 images on the page. 当我将鼠标悬停在第一张图像上时,它希望覆盖页面上的其他三张图像。 I know that to make the image hover, I have to do .img1:hover { followed by multiple attributes. 我知道要使图像悬停,我必须做.img1:hover {然后是多个属性。

I am unaware on how to make the image cover the other 3 images, as it enlarges, without having the other 3 images move. 我不知道如何在不移动其他3个图像的情况下使图像覆盖其他3个图像(随着图像放大)。 If anyone knows how to do this, please help. 如果有人知道该怎么做,请帮忙。 When I just made img1 larger, it pushed the other 3 images down, and I do not want that. 当我只是将img1 ,它会将其他3张图像下推,但我不希望这样做。

Other researched showed that using the z-index attribute might be helpful, but I am unaware on how to use it. 其他研究表明,使用z-index属性可能会有所帮助,但是我不知道如何使用它。

<div class="img1" >
</div>


<div class="img2" >
</div>


 <div class="img3" >
</div>


 <div class="img4" >
</div>

In order to use the z-index value, you will first need to set a position property other than static. 为了使用z-index值,您首先需要设置除static以外的position属性。 If you choose relative, then the images will move around as expected. 如果选择相对,则图像将按预期移动。 Then, you can set the z-index of the image you want above the others to a higher number (the default is 0). 然后,您可以将所需图像的z-index设置为更高的数字(默认值为0)。

.img1, .img2, .img3, .img4 {
float:left; position: relative; }
.img1: hover {
z-index:10; }

Demo : https://jsfiddle.net/IA7medd/qncrsq8d/ 演示: https : //jsfiddle.net/IA7medd/qncrsq8d/

.images{
  position:relative;
  overflow:hidden;
}
.img1, .img3 {
    float: left;
    max-width:49%;
}

.img2, .img4 {
    float: right;
    max-width:49%;
}

.images img{
  max-width:100%;
}

.images img:hover{
  position:absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
  max-width:100%;
  z-inedx:9;
}

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

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