CSS3过渡

时间:2012-07-30 19:11:01

标签: css css3 css-transitions

我这里有这个页面(正在进行中)http://kimwilddesigns.com/index_new.htm

在本节中,我希望能够悬停在li上,使背景图像淡出,h2淡入。这是否可以通过过渡?我可能没有正确设置,但我想看看这种效果是否可能。

<div id="categories-wrapper">
    <ul>
        <li class="fine-art"><a href="#"><img src="pics/hp_icon_fine-art.jpg" alt="fine art" width="290" height="240" border="0"></a>
            <h2>fine art work</h2>
        </li>
        <li class="gd">graphic design work</li>
        <li class="students">my students' work</li>
    </ul>
</div>

1 个答案:

答案 0 :(得分:2)

是的,这适用于CSS转换,类似于:

#categories-wrapper li a {
    position:relative;
    display: block
}

#categories-wrapper li h2 {
    position: absolute;
    left: 20px;
    top: 20px;
    opacity: 0;
}

#categories-wrapper li h2,
#categories-wrapper li img {
    -webkit-transition: opacity .3s ease-in-out;
    -moz-transition: opacity .3s ease-in-out;
    -o-transition: opacity .3s ease-in-out;
    transition: opacity .3s ease-in-out;
}

#categories-wrapper li:hover h2 {
    opacity: 1
}

#categories-wrapper li:hover img {
    opacity: 0
}

请参阅the Fiddle for this,将h2放在a标记内略微更改了标记。