如何在图像下创建阴影?

时间:2018-10-03 09:02:29

标签: html css box-shadow

我想在图像上的阴影下为悬停时的图像创建“飞行”效果。重要!图像可以具有不同的宽度(以及阴影) enter image description here

body{
  padding: 50px;
}
.images{
  list-style-type: none;
  display: flex;
  justify-content: center;
}
.images__item{
  margin-left: 10px;
  margin-right: 10px;
  background: #eee;
  padding: 30px;
  transition: .3s;
}
.images__item img{
  transition: .5s;
}
.images__item:hover {
  background: #FCF1F7;
}
.images__item:hover img{
  transform: translateY(-60px);
}
<ul class="images">
  <li class="images__item">
    <img src="https://via.placeholder.com/130x200" alt="">
  </li>
  <li class="images__item">
    <img src="https://via.placeholder.com/220x250" alt="">
  </li>
</ul>

2 个答案:

答案 0 :(得分:1)

我刚刚写这篇文章是为了向您展示概念证明,请摘下您需要的部分并在代码中使用它们。

body {
  padding: 50px;  
}

.item .image {
  width: 100px;
  height: 300px;
  background-color: red;
  position: relative;
}

.item .image:after {
  width: calc(100% + 150px);
  height: 100px;
  content: '';
  position: absolute;
  bottom: -125px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 50%;
  background-color: rgba(0,0,0,0.2);
  filter: blur(20px);
}
<div class="item">
  <div class="image"></div>
</div>

这里也是JSfiddle-https://jsfiddle.net/a5Lxp1vy/

答案 1 :(得分:-1)

这是一个很好的例子,我在这里使用div,您可以在此处放置图片:

.box {
     position: relative;
     width: 400px;
     height: 250px;
     background-color: #fff;
  
     border-radius: 1%     1%     1%     1% /     1%     1%     1%     1%;
}
.box:after {
      position: absolute;
      width: 64%;
      height: 12%;
      left: 0%;
      border-radius: 50%;
      z-index: -1;
      bottom: 0%;
      content: "";
      box-shadow: 0 50px 24px rgba(0,0,0,0.24);
}
.box>img{
  margin-left:50px;
}
<div class="box">
    <img src="https://image.ibb.co/eew9Te/html_How_to_create_shadow_under_image_Stack_Overflow.png" />
    </div>

裁剪图像的样本:

enter image description here