How to flip background image using CSS?

后端 未结 5 2147
盖世英雄少女心
盖世英雄少女心 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 06:21

    You can flip both vertical and horizontal at the same time

        -moz-transform: scaleX(-1) scaleY(-1);
        -o-transform: scaleX(-1) scaleY(-1);
        -webkit-transform: scaleX(-1) scaleY(-1);
        transform: scaleX(-1) scaleY(-1);
    

    And with the transition property you can get a cool flip

        -webkit-transition: transform .4s ease-out 0ms;
        -moz-transition: transform .4s ease-out 0ms;
        -o-transition: transform .4s ease-out 0ms;
        transition: transform .4s ease-out 0ms;
        transition-property: transform;
        transition-duration: .4s;
        transition-timing-function: ease-out;
        transition-delay: 0ms;
    

    Actually it flips the whole element, not just the background-image

    SNIPPET

    function flip(){
    	var myDiv = document.getElementById('myDiv');
    	if (myDiv.className == 'myFlipedDiv'){
    		myDiv.className = '';
    	}else{
    		myDiv.className = 'myFlipedDiv';
    	}
    }
    #myDiv{
      display:inline-block;
      width:200px;
      height:20px;
      padding:90px;
      background-color:red;
      text-align:center;
      -webkit-transition:transform .4s ease-out 0ms;
      -moz-transition:transform .4s ease-out 0ms;
      -o-transition:transform .4s ease-out 0ms;
      transition:transform .4s ease-out 0ms;
      transition-property:transform;
      transition-duration:.4s;
      transition-timing-function:ease-out;
      transition-delay:0ms;
    }
    .myFlipedDiv{
      -moz-transform:scaleX(-1) scaleY(-1);
      -o-transform:scaleX(-1) scaleY(-1);
      -webkit-transform:scaleX(-1) scaleY(-1);
      transform:scaleX(-1) scaleY(-1);
    }
    Some content here

提交回复
热议问题