Can you use CSS to mirror/flip text?

后端 未结 14 2248
旧时难觅i
旧时难觅i 2020-11-28 01:27

Is it possible to use CSS/CSS3 to mirror text?

Specifically, I have this scissors char “✂” () that I\'d like to display pointing left a

相关标签:
14条回答
  • 2020-11-28 01:58

    You can use CSS transformations to achieve this. A horizontal flip would involve scaling the div like this:

    -moz-transform: scale(-1, 1);
    -webkit-transform: scale(-1, 1);
    -o-transform: scale(-1, 1);
    -ms-transform: scale(-1, 1);
    transform: scale(-1, 1);
    

    And a vertical flip would involve scaling the div like this:

    -moz-transform: scale(1, -1);
    -webkit-transform: scale(1, -1);
    -o-transform: scale(1, -1);
    -ms-transform: scale(1, -1);
    transform: scale(1, -1);
    

    DEMO:

    span{ display: inline-block; margin:1em; } 
    .flip_H{ transform: scale(-1, 1); color:red; }
    .flip_V{ transform: scale(1, -1); color:green; }
    <span class='flip_H'>Demo text &#9986;</span>
    <span class='flip_V'>Demo text &#9986;</span>

    0 讨论(0)
  • 2020-11-28 01:58

    You can user either

    .your-class{ 
          position:absolute; 
          -moz-transform: scaleX(-1); 
          -o-transform: scaleX(-1); 
          -webkit-transform: scaleX(-1); 
          transform: scaleX(-1); 
          filter: FlipH;  
    }
    

    or

     .your-class{ 
      position:absolute;
      transform: rotate(360deg) scaleX(-1);
    }
    

    Notice that setting position to absolute is very important! If you won't set it, you will need to set display: inline-block;

    0 讨论(0)
  • 2020-11-28 01:58

    this is what worked for me for <span class="navigation-pipe">&gt;</span>

    display:inline-block;
    -moz-transform: rotate(360deg);
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=4);
    

    just need display:inline-block or block to rotate. So basically first answer is good. But -180 didn't worked.

    0 讨论(0)
  • 2020-11-28 02:00

    For cross browser compatibility create this class

    .mirror-icon:before {
        -webkit-transform: scale(-1, 1);
        -moz-transform: scale(-1, 1);
        -ms-transform: scale(-1, 1);
        -o-transform: scale(-1, 1);
        transform: scale(-1, 1);
    }
    

    And add it to your icon class, i.e.

    <i class="icon-search mirror-icon"></i>
    

    to get a search icon with the handle on the left

    0 讨论(0)
  • 2020-11-28 02:01
    -moz-transform: scale(-1, 1);
    -webkit-transform: scale(-1, 1);
    -o-transform: scale(-1, 1);
    -ms-transform: scale(-1, 1);
    transform: scale(-1, 1);
    

    The two parameters are X axis, and Y axis, -1 will be a mirror, but you can scale to any size you like to suit your needs. Upside down and backwards would be (-1, -1).

    If you're interested in the best option available for cross browser support back in 2011, see my older answer.

    0 讨论(0)
  • 2020-11-28 02:01

    Just adding a working demo for horizontal and vertical mirror flip.

    .horizontal-flip {
      -moz-transform: scale(-1, 1);
      -webkit-transform: scale(-1, 1);
      -o-transform: scale(-1, 1);
      -ms-transform: scale(-1, 1);
      transform: scale(-1, 1);
    }
    
    .vertical-flip {
      -moz-transform: scale(1, -1);
      -webkit-transform: scale(1, -1);
      -o-transform: scale(1, -1);
      -ms-transform: scale(1, -1);
      transform: scale(1, -1);
    }
    <div class="horizontal-flip">
      Hello, World
      <input type="text">
    </div>
    <hr>
    <div class="vertical-flip">
      Hello, World
      <input type="text">
    </div>

    0 讨论(0)
提交回复
热议问题