【问题标题】:How to create shadow under image?如何在图像下创建阴影?
【发布时间】:2019-03-08 11:14:21
【问题描述】:

我想为悬停时的图像创建“飞行”效果,并在图像下添加阴影。重要的!图像可以有不同的宽度(以及阴影)

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>

【问题讨论】:

  • 使用伪元素并提高模糊效果
  • @AndyHolmes 你能举一个这种模糊的例子吗?
  • 是的,等一下,我看看能不能快点搞定
  • 我看到人们正在回答您的问题以寻求奖励,但他们不会打扰您投票。这是一个好问题,所以我投了赞成票,也许其他人也应该这样做。 :)

标签: html css box-shadow


【解决方案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/

【讨论】:

【解决方案2】:

这是一个很好的例子,我在这里使用了一个 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>

裁剪图像的示例:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 2013-01-17
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多