CSS3悬停和活动问题

时间:2013-05-21 23:14:15

标签: css html5

尝试制作CSS功能图:

CSS

.fader-us {
    display: none;
}

.fader-us-content {
    display: none;
    position: fixed;
    top:50px;
    left:50px;
    z-index:81;
}
    .fader-us:active .fader-us-content {
        display:block;
    }
        .fader-us:active .us {
            opacity:0;
        }

    .fader-us-content:hover {
        display: block;
    }
        .fader-us-content:hover .us {
            opacity:0;
        }

        .fader-us img {
            line-height: 0;
            z-index:79;
            -webkit-transition: all 0.3s ease;
            -moz-transition:    all 0.3s ease;
            -o-transition:      all 0.3s ease;
            -ms-transition:     all 0.3s ease;
            transition:         all 0.3s ease; 
        }

        .us {
            position:fixed;
            top:33px;
            left:55px;
            z-index:0;
        }

HTML

        <div class="fader-us">
            <img class ="us" src="us.png" alt="">
            <div class="fader-us-content">
                <li>California</li>
                <li>Florida</li>
            </div>
        </div>

我试图做的是当我的鼠标结束“fader-us-content”时,让us.png img消失。 无法弄清楚为什么只有当我一直点击时图像才会消失。

小提琴

http://jsfiddle.net/r9qHa/

3 个答案:

答案 0 :(得分:1)

尝试更改此内容:

    <div class="fader-us">
        <img class ="us" src="us.png" alt="">
        <div class="fader-us-content">
            <li>California</li>
            <li>Florida</li>
        </div>
    </div>

.fader-us:active .fader-us-content {
        display:block;
    }

To This:

<div class="fader-us">
        <img class ="us" src="us.png" alt="">
        <div class="fader-us-content">
          <ul>
            <li>California</li>
            <li>Florida</li>
          </ul>
        </div>
    </div>

.fader-us:active .fader-us-content:hover {
        display:block;
    }

答案 1 :(得分:1)

使用'〜'可能是个好方法:

.fader-us-content:hover~.us {
    opacity:0;
}

像这样更改html:

<div class="fader-us">
    <div class="text">
        <p>USAs</p>
    </div>
    <ul class="fader-us-content">
        <li>California</li>
        <li>Florida</li>
    </ul>
    <img class ="us" src="http://s23.postimg.org/rixm8ire3/image.png" alt=""/>
</div>

jsfiddle.net

答案 2 :(得分:1)

Working FIDDLE Demo

在样式的末尾添加此规则:

.fader-us:hover .fader-us-content {
    display:block;
}

.fader-us:hover .us { opacity: 0; }