我的css过渡不起作用

时间:2014-04-20 18:33:52

标签: javascript jquery html css

我有一个带有p标签的li,只有在你悬停li时才显示,但是我无法在它之间进行转换,我该怎么做?也许这只是javascript javascript javascript,我不知道如何解决这个问题

<ul class="promo-line two">
    <li>
        <p>36%</p>
    </li>
    <li>
        <p>45%</p>
    </li>
    <li>
        <p>50%</p>
    </li>
</ul>

并且:

* {margin:0;padding:0;}

.promo-line.two li:nth-child(1) {
    background: red;
}

.promo-line.two li:nth-child(2) {
    background: blue;
}

.promo-line.two li:nth-child(3) {
    background: yellow;
}

.promo-line li p {
    display: none;
    transition: all 1s ease-in-out;
}

.promo-line li:hover > p {
    display: block;
    background: rgba(0,0,0,0.5);
    color: white;
    width: 314px;
    height: 180px;
    line-height: 180px;
    text-align: center;
    font-size: 25px;
    box-shadow: inset 5px 5px 40px black;
}

.promo-line li {
    position: relative;
    width: 314px;
    height: 180px;
    margin: 0 0 0 4px;
    float: left;
    background: purple;
}

1 个答案:

答案 0 :(得分:2)

请参阅http://jsfiddle.net/GB4QL/2/

您需要使用opacity属性而不是display

  * {margin:0;padding:0;}

.promo-line.two li:nth-child(1) {
    background: red;
}

.promo-line.two li:nth-child(2) {
    background: blue;
}

.promo-line.two li:nth-child(3) {
    background: yellow;
}

.promo-line li p {
    opacity: 0;
    background: rgba(0,0,0,0.5);
    color: white;
    width: 314px;
    height: 180px;
    min-height:180px;
    line-height: 180px;
    text-align: center;
    font-size: 25px;
    box-shadow: inset 5px 5px 40px black;
    transition: all 1s ease-in-out;
}

.promo-line li:hover > p {
    opacity: 1;

}

.promo-line li {
    position: relative;
    width: 314px;
    height: 180px;
    margin: 0 0 0 4px;
    float: left;
    background: purple;
}