Search code examples
csspolymer

How to flip iron-icon vertically in css


I'm using iron-icon components for my Polymer 2 application, and I want to know how to flip these icons vertically or horizontally? I've tried the transform attribute and equivalent for other browsers, but it didn't work for me. as below:

.my-icon-class {
    color: #55555A;
    margin-top: 10px;
    width: 30px;
    height: 50px;
    transform: scale(-1);
}

I've even tried ´filter´ attributte on IE:

.my-icon-class {
    color: #55555A;
    margin-top: 10px;
    width: 30px;
    height: 50px;
    filter: FLipH;
}

And my icon instantiation looks like:

<iron-icon class="my-icon-class" icon="icons:room"></iron-icon>

The imports statement goes like this:

<link rel="import" href="../../bower_components/polymer/polymer-element.html">

<link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">

You can find a snippest here below:

// Load webcomponents.js polyfill if browser doesn't support native Web Components.
var webComponentsSupported = (
  'registerElement' in document
  && 'import' in document.createElement('link')
  && 'content' in document.createElement('template')
);

if (webComponentsSupported) {
	// For native Imports, manually fire WebComponentsReady so user code
  // can use the same code path for native and polyfill'd imports.
  if (!window.HTMLImports) {
    document.dispatchEvent(
      new CustomEvent('WebComponentsReady', {bubbles: true})
    );
  }
} else {
	// Load webcomponents.js polyfill
  var script = document.createElement('script');
  script.async = true;
  script.src = 'https://cdn.rawgit.com/StartPolymer/cdn/1.8.1/components/webcomponentsjs/webcomponents-lite.min.js';
  document.head.appendChild(script);
}
h1 {
  font-size: 24px;
  font-weight: 500;
  line-height: 32px;
  margin: 24px 0;
}

.my-icon-class {
  color: #55555A;
  margin-top: 10px;
  width: 50px;
  height: 70px;
}
<!-- <base href="https://gitcdn.xyz/cdn/StartPolymer/cdn/v1.11.0/components/"> -->
<!-- <base href="https://cdn.rawgit.com/StartPolymer/cdn/v1.11.0/components/"> -->
<base href="https://rawcdn.githack.com/StartPolymer/cdn/v1.11.0/components/">

<link rel="import" href="iron-icon/iron-icon.html">
<link rel="import" href="iron-icons/iron-icons.html">

<style is="custom-style">

body {
  @apply(--layout-vertical);
  @apply(--layout-center-center);
}
</style>

<h1>Polymer Icon to Flip</h1>
<p>And I want to flip it vertically and/or horizontally, need only the css. Thanks</p>

<iron-icon class="my-icon-class" icon="icons:room"></iron-icon>
icon to flip

<script>

window.addEventListener('WebComponentsReady', function() {
  // Async call needed here for IE11 compatibility.
  Polymer.Base.async(function() {
    
  });
});

</script>

If need more info plz ask in comments.


Solution

  • I found a solution by using:

    .my-class {
        transform: rotate(180deg);
    }