CSS 响应式卡片

想实现的效果

最开始是看到了华为网站的这个卡片效果,想复刻一下。

效果细分

  1. 在普通状态下,为了让白字显示更清楚,图片前有一个渐变阴影的蒙版。
  2. 鼠标移入后,渐变阴影加深,图片放大,下方文字浮出。
  3. 鼠标移到了解更多时,箭头向右移动

代码实现 

HTML

<div class="card">
    <img src="../assets/img/hongkong.jpeg"/>
    <!--mask用于添加阴影-->
    <div class="mask"></div>
    <div class="caption">
        <h3 class="text"> 旅游 </h3>
        <h2 class="text"> 香港的景色</h2>
        <p class="text2"> 了解更多 </p>
    </div>  
</div>

CSS 

.card{
    width: 450px;
    background-size: cover;
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}
img{
    display: block; /*删除此行,父盒子高度会出现超出*/
    width: 100%;
    transition: all 0.5s;
}
.caption{
    width:100%;
    position: absolute;
    bottom: -26px;
    margin: 0px;
    transition: all 0.5s;
}

/*鼠标移入,图片放大*/
.card:hover img{
    transform: scale(1.1);
}
/*鼠标移入,文字上升*/
.card:hover .caption{
    transform: translateY(-40px);
}

.mask{
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
}

/*鼠标移入,渐变阴影加深*/
.card:hover .mask{
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.4));
}

.text{
    color: rgba(255,255,255);
    padding: 0px 0px 5px 16px;
    margin: 0px;
    user-select: none;
}
.text2{
    color: rgba(255,255,255);
    padding: 5px 0px 10px 16px;
    margin: 0px;
    user-select: none;
}

.text2::after{
    content: ">";
    color:rgb(158, 218, 255);
    font-size: large;
    font-weight: bolder;
    transition: 0.5s;
}

/*鼠标移入,箭头右移*/
.text2:hover::after{
    padding-left: 5px;
} 

最终效果

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值