4

I'm trying to rotate the double angle bracket set as the content in an :after pseudo-element using the css transform value rotate(90deg) for a tab across the top of the screen. Here's the relevant code:

.header {
  -moz-transition: top .5s ease;
  -webkit-transition: top .5s ease;
  -o-transition: top .5s ease;
  transition: top .5s ease;
  position: absolute;
  left: 0;
  right: 0;
  top: -60px;
  height: 80px;
  background-color: #2d2;
}

.header.in-top {
  top: 0;
}

.header-tab {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 20px;
  text-align: center;
  color: #000;
  -moz-transition: color .5s ease;
  -webkit-transition: color .5s ease;
  -o-transition: color .5s ease;
  transition: color .5s ease;
}

.header-tab:hover {
  color: #e22;
}

.header-arrow:after {
  font-size: 20px;
  line-height: 1;
  -moz-transform: rotate(90deg);
  -webkit-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  -o-transform: rotate(90deg);
  transform: rotate(90deg);
}

.header .header-arrow:after {
  content: "\00bb";
}

.header.in-top .header-arrow:after {
  content: "\00ab";
}
<div class="header">
  <div class="header-tab" data-toggle="in-top">
    <span class="header-arrow"></span>
  </div>
</div>

The data-toggle attribute is used in JavaScript to toggle the in-top class in order to switch the direction of the double angle bracket as well as to expose the content of the header by bringing it down. The transform properties I have specified seem to do nothing though. Any solutions?

Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153

3 Answers3

7

Use display: inline-block on the pseudo-element. Alternatively, inline-table or block should also work.

See jsFiddle.

Your pseudo-element is displayed inline by default, which makes it a nontransformable element. From the CSS Transforms Working Draft specification:

transformable element

A transformable element is an element in one of these categories: an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose ‘display’ property computes to ‘table-row’, ‘table-row-group’, ‘table-header-group’, ‘table-footer-group’, ‘table-cell’, or ‘table-caption’

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
1

You need to set the pseudo-element as a block or inline-block element:

.header-arrow:after {
  display: block;
}

The specification says rotation should work on inline elements, but in WebKit based browsers it doesn't works: https://www.webkit.org/blog/130/css-transforms/

pzin
  • 4,200
  • 2
  • 28
  • 49
  • I just read the same specification and it should *not* work on inline elements, did I miss something? – rink.attendant.6 Aug 15 '13 at 04:21
  • I think *[atomic inline-level elements](http://www.w3.org/TR/CSS2/visuren.html#x13)* are also inline elements. – pzin Aug 15 '13 at 04:30
  • I can understand why that's confusing because the wording of the spec for the definition of *atomic inline-level elements* can definitely be written better. However from my understanding from the [MDN article](https://developer.mozilla.org/en-US/docs/Web/CSS/Visual_formatting_model), atomic inline-level elements cannot be split into multiple lines/boxes, which disqualifies `display: inline` and explains why the transformation wasn't working. – rink.attendant.6 Aug 15 '13 at 05:12
0

Rotate property will apply on pseudo-element(after/before) only when you will use display:inline-block; or display:inline-block; property in your class or selector.

.className:before{
   -webkit-transform: rotateZ(180deg); /* Safari */
  transform: rotateZ(180deg); /* Standard syntax */
    display: inline-block;
}
Billu
  • 2,733
  • 26
  • 47