CSS实现鼠标悬停图片上升显示


前言

当我们想在图片上面放置一些文字内容时,发现不管怎么放置,要么就是图片影响到文字的观感,要么就是文字挡住图片的细节,那么怎么可以既看到图片的细节又可以看到对图片的文字描述呢?本文给大家分享纯CSS实现鼠标悬停图片上升显示描述案例,感兴趣的朋友一起看看吧


一、实现效果

在这里插入图片描述

二、实现思路

我们需要将外层的盒子设置相对定位,将其子盒子设置绝对定位,形成子绝父相,当我们触摸图片时,通过 bottom 属性搭配 transition 属性让其以丝滑的动画实现图片上升显示描述的效果。
代码如下(示例):

<template>
  <div class="parentBox">
    <div class="imgBox">
      <img src="https://i.postimg.cc/4xxZNsL6/1677486088618.png">
    </div>
    <div class="contantBox">详细内容</div>
  </div>
</template>
<style scoped>
.parentBox {
  box-shadow: 2px 2px 8px -1px cornflowerblue;
  width: 200px;
  height: 200px;
  position: relative;
  cursor: pointer;
}

.imgBox {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 20;
  -webkit-transition: all 0.5s ease;
  transition: all 0.5s ease;
  bottom: 0;
}
img {
  width: 100%;
  height: 100%;
}

.parentBox:hover .imgBox {
  bottom: 60px;
}

.contantBox {
  padding: 4px;
  color: white;
  width: 100%;
  height: 60px;
  background: cornflowerblue;
  position: absolute;
  bottom: 0;
}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我慢慢地也过来了

谢谢大佬的投喂

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值