How to flip background image using CSS?

后端 未结 5 2148
盖世英雄少女心
盖世英雄少女心 2020-12-04 05:29

How to flip any background image using CSS? Is it possible?

currenty I\'m using this arrow image in a background-image of li in css

5条回答
  •  难免孤独
    2020-12-04 05:55

    According to w3schools: http://www.w3schools.com/cssref/css3_pr_transform.asp

    The transform property is supported in Internet Explorer 10, Firefox, and Opera. Internet Explorer 9 supports an alternative, the -ms-transform property (2D transforms only). Safari and Chrome support an alternative, the -webkit-transform property (3D and 2D transforms). Opera supports 2D transforms only.

    This is a 2D transform, so it should work, with the vendor prefixes, on Chrome, Firefox, Opera, Safari, and IE9+.

    Other answers used :before to stop it from flipping the inner content. I used this on my footer (to vertically-mirror the image from my header):

    HTML:

    
    

    CSS:

    footer {
    background:url(/img/headerbg.png) repeat-x 0 0;
    
    /* flip background vertically */
    -webkit-transform:scaleY(-1);
    -moz-transform:scaleY(-1);
    -ms-transform:scaleY(-1);
    -o-transform:scaleY(-1);
    transform:scaleY(-1);
    }
    
    /* undo the vertical flip for all child elements */
    footer * {
    -webkit-transform:scaleY(-1);
    -moz-transform:scaleY(-1);
    -ms-transform:scaleY(-1);
    -o-transform:scaleY(-1);
    transform:scaleY(-1);
    }
    

    So you end up flipping the element and then re-flipping all its children. Works with nested elements, too.

提交回复
热议问题