简体   繁体   English

将鼠标悬停在效果上将图像向下

[英]Hover over effect pushing image down

Here is an image of the media div with the on hover X I have: 这是带有我on hover Xmedia div的图像:

在此处输入图片说明

Here is an image of when you click on the div and upload a photo. 这是单击div并上传照片时的图像。 As you can see it fits nicely inside the box. 如您所见,它非常适合包装盒。

在此处输入图片说明

Finally here is a div when I hover over the image to see the X . 最后,当我将hover over图像上以查看X时,这是一个div。

在此处输入图片说明

As you can see the image got pushed down. 如您所见,图像被推下。 My end result is instead to have it hover over the image and not affect the images placement 我的最终结果是将其悬停在图像上,并且不影响图像的放置

Here's my CSS: 这是我的CSS:

.x {
  color:red;
  #width:50px;
  #height:50px;
  display:none;
  #left:50px;
}
.MediaPreview:hover > .x {
  display:block;
}
.MediaPreview {
    position: absolute;
    width: 128px;
    height: 72px;
    background-color: #e0e0e0;
    cursor: default;
}

Here is my HTML: 这是我的HTML:

<div class="MediaPreview" style="left: 10px; bottom: 10px;">
  <span>Image or video, required</span>
   <div class="x">x</div>
</div>

Try this? 尝试这个?

.x {
  color:red;
  #width:50px;
  #height:50px;
  display:none;

  top: 10px;
  left: 10px;
  position: absolute;
  z-index: 1;

}
.MediaPreview:hover > .x {
  display:block;
}
.MediaPreview {
    position: absolute;
    width: 128px;
    height: 72px;
    background-color: #e0e0e0;
    cursor: default;
}

You need to apply position:absolute to .x , not .MediaPreview . 您需要将position:absolute应用于.x ,而不是.MediaPreview Try this: 尝试这个:

.x {
  color:red;
  display:none;
  position: absolute;
  top: 0;
  left: 0;
}
.MediaPreview:hover > .x {
  display:block;
}
.MediaPreview {
    position: relative;
    width: 128px;
    height: 72px;
    background-color: #e0e0e0;
    cursor: default;
}

This is how to get the job done. 这是完成工作的方法。 Using pure css 使用纯CSS

<div class="mediapreview">

<a href="#" class="upsize red">X</a>

<img src="http://hub.n2growth.com/wp-content/uploads/2012/04/About-People-2.jpg" alt="people" class="responsive">

</div>

DEMO 演示

you can try this: https://jsfiddle.net/maky/gqn1nrxj/ 您可以尝试以下方法: https : //jsfiddle.net/maky/gqn1nrxj/

.x {
  color:red;
  display:none;
  position: absolute;
  top: 0;
  left: 0;
}
.MediaPreview:hover > .x {
  display:block;
}
.MediaPreview {
    position: relative;
    padding:10px;
    width: 200px;
    height: 200px;
    background-color: #e0e0e0;
    cursor: default;
}

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

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