Search code examples
csscss-selectorscss-transformspseudo-class

CSS: pseudo selector for transformed elements


Is there a (future) pseudo selector to get elements which have been transformed by the css transform property? i think of something like this:

div:transformed{
 color:red;
}

Solution

  • There is no such pseudo selector. The following javascript code might serve your purpose:

    var element = document.querySelectorAll('div');
    for (i = 0; i < element.length; i++) {
      var value = window.getComputedStyle(element[i]).getPropertyValue("transform");
      if (value != "") //Or suitable comparator
      {
        element[i].style.color = "red";
      }
    }
    div {
      transform: translateX(10px);
    }
    <div>Text</div>