利用transition过渡实现hover效果出现一个背景样式

一、首先构建一个html结构

先引入一个基础样式base.css,再引入一个首页样式index.css。

创建结构li里面用超链接a包裹主体内容,兄弟标签div创建需要移出的背景样式

 <link rel="stylesheet" href="./base.css">
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <div class="hot clearfix">
        <div class="bd wrapper">
            <ul>
                <li>
                    <a href="#">
                        <div class="pic"><img src="./images/1.webp" alt=""></div>
                        <div class="info">
                            <h4>双味千层,手抓饼烤肉组合</h4>
                        </div>
                    </a>
                    <div class="cover" style="text-align: center;">
                        <p><img src="./images/1.png" alt=""></p>
                        <p><img src="./images/2.png" alt="" class="one">口水菌品鉴 | 宅男宅女觅食记<img src="./images/3.png" alt=""
                                class="two"></p>
                        <p><a href="">立即查看</a></p>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</body>

二、css样式

base.css就是最基本的清除默认样式代码

/* 基础公共样式:清除默认样式 + 设置通用样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

li {
  list-style: none;
}

body {
  font: 14px/1.5 "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif;
  color: #333;
}

a {
  color: #333;
  text-decoration: none;
}

a:hover {
  color: red;
}

.clearfix::before,
.clearfix::after {
  content: "";
  display: table;
  clear: both;
}

.wrapper {
  margin: 0 auto;
  width: 1280px;
}

index.css是首页需要的样式

.hot {
    margin-top: 100px;
}

.bd li {
    float: left;
    margin-right: 20px;
    position: relative;
    height: 160px;
    margin-bottom: 20px;
    overflow: hidden;
}

.bd li:last-of-type {
    margin-right: 0;
}

.hot .bd .pic img {
    width: 400px;
}

.hot .bd .info {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 400px;
    text-align: center;
    background-color: rgba(255, 192, 203, .5);
    line-height: 30px;
}

/* 产品底部绿色区域 */
.hot .bd li .cover {
    position: absolute;
    left: 0;
    bottom: -160px;
    padding-top: 20px;
    width: 400px;
    height: 160px;
    background-color: rgba(104, 102, 84, .5);
    text-align: center;
    color: #fff;
    transition: all 0.5s;
}

.hot .bd .cover p {
    margin: auto;
}

.hot .bd .cover p:nth-child(1) {
    font-size: 18px;
}

.hot .bd .cover p:nth-child(2) {
    position: relative;
    width: 260px;
    border-bottom: 1px solid #000;
    line-height: 30px;
    background-color: rgba(255, 255, 255, 0.11);
}

.hot .bd .cover p:nth-child(2) img.one {
    position: absolute;
    top: 0px;
    left: 5px;
}

.hot .bd .cover p:nth-child(2) img.two {
    position: absolute;
    top: 0px;
    right: 5px;
}

.hot .bd .cover p:nth-child(3) {
    font-size: 13px;
    width: 100px;
    margin-top: 5px;
    border-radius: 5px;
    border: 1px solid #000;
}


/* 鼠标悬停到li,显示cover,改变位置 */
.hot .bd li:hover .cover {
    bottom: 0px;
}

.hot .bd li:hover {
    border: 2px solid #00BE9A;
}

使用transition实现过渡效果,设置时间等属性

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

趋之

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值