Does :before not work on img elements?

后端 未结 12 2245
眼角桃花
眼角桃花 2020-11-22 01:46

I\'m trying to use the :before selector to place an image over another image, but I\'m finding that it simply doesn\'t work to place an image before an im

12条回答
  •  广开言路
    2020-11-22 02:27

    Here's another solution using a div container for img while using :hover::after to achieve the effect.

    The HTML as follows:

    The CSS as follows:

    #img_container { 
        margin:0; 
        position:relative; 
    } 
    
    #img_container:hover::after { 
        content:''; 
        display:block; 
        position:absolute; 
        width:300px; 
        height:300px; 
        background:url(''); 
        z-index:1; 
        top:0;
    } 
    

    To see it in action, check out the fiddle I've created. Just so you know this is cross browser friendly and there's no need to trick the code with 'fake content'.

提交回复
热议问题