CSS3 background image transition

前端 未结 13 2425
梦如初夏
梦如初夏 2020-11-22 07:07

I\'m trying to make a \"fade-in fade-out\" effect using the CSS transition. But I can\'t get this to work with the background image...

The CSS:



        
13条回答
  •  星月不相逢
    2020-11-22 07:52

    You can use pseudo element to get the effect you want like I did in that Fiddle.

    CSS:

    .title a {
        display: block;
        width: 340px;
        height: 338px;
        color: black;
        position: relative;
    }
    .title a:after {
        background: url(https://lh3.googleusercontent.com/-p1nr1fkWKUo/T0zUp5CLO3I/AAAAAAAAAWg/jDiQ0cUBuKA/s800/red-pattern.png) repeat;
        content: "";
        opacity: 0;
        width: inherit;
        height: inherit;
        position: absolute;
        top: 0;
        left: 0;
        /* TRANSISITION */
        transition: opacity 1s ease-in-out;
        -webkit-transition: opacity 1s ease-in-out;
        -moz-transition: opacity 1s ease-in-out;
        -o-transition: opacity 1s ease-in-out;
    }
    .title a:hover:after{   
        opacity: 1;
    }
    

    HTML:

    
    

提交回复
热议问题