【问题标题】:css transition not working for display: none [duplicate]CSS过渡不适用于显示:无[重复]
【发布时间】:2016-11-14 20:30:30
【问题描述】:

不知道为什么过渡不起作用

因此,想法是带有一些文本的块应该在 :hover 上可见。 它作为非悬停状态的预期工作(隐藏文本认为 rgba)

我尝试了 all 和 display 属性。我还尝试为所有元素添加过渡,例如 h3 和 p。

请访问 https://jsfiddle.net/dyrc522f/

<div class="photo photo2">Some title
                <div class="photobl photobl2">
                    <h3>Some title</h3>
                    <p>text</p>
                </div> 
            </div>

css

.photo{
    width: 244px;
    height: 219px;
    float: left;
    color: #fff;
    position: relative;
    font-size: 23px;
    font-weight: 700;
    text-align: center;
    padding-top: 180px;
    -webkit-transition:all .4s ease;
    -moz-transition:all .4s ease;
    -ms-transition:all .4s ease;
    transition: all .4s ease;

  background-color: tomato;/**/
    }
.photo:hover{
    color: rgba(0, 0, 0, 0);
}
.photo:hover .photobl{
    display: block;
}
.photobl{
    display: none;
    width: 244px;
    height: 399px;
    position: absolute;
    background: rgba(0, 0, 0, 0.5) url('../images/logomin.png') center 40px no-repeat;
    top: 0;
    -webkit-transition: display .4s ease;
    -moz-transition: display .4s ease;
    -ms-transition: display .4s ease;
    transition: display .4s ease;
    }
.photobl h3{
    font-size: 23px;
    font-weight: 700;
    color: #ffcc00;
    padding-top: 181px;
    padding-bottom: 30px;
    }
.photobl p{
    font-size: 16px;
    font-weight: 300;
    color: #fff;
    line-height: 1.3;
    }

【问题讨论】:

    标签: html css


    【解决方案1】:

    您可以将过渡用于不透明度,但不能用于显示。一个伟大的、完整的答案在这里:CSS3 transition doesn't work with display property

    【讨论】:

    • 没错。我很愚蠢 :) 感谢您的帮助!
    • 谢尔盖不用担心。你一点也不傻。在我意识到这个有什么问题之前,我拿了一些headdesk。 :)
    猜你喜欢
    • 2023-02-18
    • 2014-04-01
    • 2020-05-26
    • 2014-09-14
    • 1970-01-01
    • 2018-12-13
    • 2021-07-27
    • 2015-01-02
    • 2015-11-01
    相关资源
    最近更新 更多