Marian Rick Marian Rick - 1 year ago 105
CSS Question

How to rotate pseudo element css

I want to recreate this icon using css pseudo elements (as a toggle indicator):

enter image description here

I have created the nececcary pseudo elements using

::after, ::before
and tried to rotate them using
transform: rotate(90deg)

How can I tell them to rotate around their own center? I have tried
transform-origin: 50% 50%;
which does not work. Right now, both pseudo elements got the same
right: 10px;
but they are not placed above each other, instead they are next to each other.

You can check this JS FIDDLE to illustrate the problem.

Answer Source

transform-origin works fine, it's just that

a) 50% 50% (the object's center) is the default, and

b) you have to center the content of the box. That's a bit tricky because the icon you use doesn't require the full line height. Try adding

::before, ::after {
  padding-bottom: .17em;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download