过渡效果失效
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来让文字隐藏,但是过渡效果失效了
7
收起
正在回答
1回答
同学你好,display属性本身没有过渡效果,block显示,none隐藏,中间没有过渡阶段。例如opacity透明度,0是完全透明,1是不透明,还可以有中间值0.1,0.2,0.3等,这样的属性是可以设置过渡效果的。
建议这里换为opacity属性
祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧