Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform :before or :after item

Tags:

css

Is there a way to apply transform onto an element inserted with :before?

The following does not work, but I'm open to other solutions.

.itemclass:before  {
  content: "➨";
  transform: rotate(30deg);
  -ms-transform: rotate(30deg); /* IE 9 */
  -webkit-transform: rotate(30deg); /* Safari and Chrome */
}
like image 401
Dean Smith Avatar asked Apr 19 '13 15:04

Dean Smith


People also ask

How does a transform scale work?

This scaling transformation is characterized by a two-dimensional vector. Its coordinates define how much scaling is done in each direction. If both coordinates are equal, the scaling is uniform (isotropic) and the aspect ratio of the element is preserved (this is a homothetic transformation).

How does transform work in CSS?

Definition and Usage. The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements.

What is the use of transform origin?

Definition and Usage The transform-origin property allows you to change the position of transformed elements. 2D transformations can change the x- and y-axis of an element. 3D transformations can also change the z-axis of an element. To better understand the transform-origin property, view a demo.


1 Answers

Transforms can't be applied to non-replaced inline elements. Add:

display:inline-block;

Demo

Side-note: Though this doesn't apply to this use case, absolute/fixed positioning would discard the need for a display property as these are automatically treated as display:block.

Also, check the definition of transformable element:

A transformable element is an element in the HTML namespace 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’; or an element in the SVG namespace (see [SVG11]) which has the attributes ‘transform’, ‘patternTransform’ or ‘gradientTransform’.

like image 71
Fabrício Matté Avatar answered Sep 20 '22 19:09

Fabrício Matté