过渡效果失效

过渡效果失效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,minimal-ui:ios">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="">
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            position: relative;
            width: 300px;
            height: 166px;
            margin: 20px auto;
            
        }
        div img{
            width: 300px;
            height: 166px;
            
        }
        div p{
            display: none;
            position: absolute;
            bottom: 0;
            left: 0;
            width: 300px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            background-color: rgba(51, 49, 49, 0.5);
            color: #fff;
            transition: all 5s linear 0s;
        }
        div:hover p{
            display: block;
        }
    </style>
</head>
 
<body>
    <div>
        <img src="./images/0.jpg" alt="">
        <p>北京故宫</p>
    </div>
</body>
 
</html>

问题描述:

老师我用display:none来让文字隐藏,但是过渡效果失效了

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,display属性本身没有过渡效果,block显示,none隐藏,中间没有过渡阶段。例如opacity透明度,0是完全透明,1是不透明,还可以有中间值0.1,0.2,0.3等,这样的属性是可以设置过渡效果的。

建议这里换为opacity属性

https://img1.sycdn.imooc.com//climg/62ce35f60930e54e06260468.jpg

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码