You know that flag emoji (🇺🇸) from a couple posts ago?
Wonder how I got it to rotate like the House of Cards graphic?
Easy. CSS3!
-
I wrapped the flag emoji (🇺🇸) in a
<span>
tag and applied an inline style rule[1] -
Next, I used the CSS3 property
transform
[2] with therotate: ();
value like so:transform: rotate(-180deg);
-
This didn’t work.
The result for the following markup
I know who I'm voting for <span style="transform: rotate(-180deg);">🇺🇸</span>
was
I know who I’m voting for 🇺🇸
The flag wasn’t upside-down as I had hoped.
What was the problem?
-
Turns Outâ„¢ I needed to force the desired-text-to-be-rotated to
inline-block
(orblock
), because<span>
is, by definition, an inline elementIt’s wonky to expect the flag emoji (🇺🇸) to rotate when it’s still the child of a
<p>
that is not styled to rotate. -
So, I applied the
display
property with the valueinline-block
and added it to the markup like soI know who I'm voting for <span style="display: inline-block; transform: rotate(-180deg);">🇺🇸</span>
resulting in
I know who I’m voting for 🇺🇸
I did this because it’s not worth adding a custom class to my main stylesheet just for this one random style change. ↩
Technically, I should have used the
-webkit
prefix ala-webkit-transform
, but I’m lazy, and I’m pretty sure thetransform
property has been adopted by most every browser that matters. So why add additional prefix cruft when it’s more or less unnecessary? ↩