css过渡不适用于display:none

时间:2016-07-12 14:22:10

标签: html css

无法弄清楚为什么过渡不起作用

所以,我们的想法是在一些文本块上应该可见:hover。 它作为非悬停状态的诠释(隐藏文本思想rgba)

我尝试了所有并显示属性。我还尝试向所有元素添加过渡,例如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;
    }

1 个答案:

答案 0 :(得分:3)

您可以使用转换为不透明度但不显示。这里有一个很好的,完整的答案:CSS3 transition doesn't work with display property