Transform Origin

Tailwind CSS version

v1.2.0+

Utilities for specifying the origin for an element’s transformations.

Class reference

Class
Properties
.origin-centertransform-origin: center;
.origin-toptransform-origin: top;
.origin-top-righttransform-origin: top right;
.origin-righttransform-origin: right;
.origin-bottom-righttransform-origin: bottom right;
.origin-bottomtransform-origin: bottom;
.origin-bottom-lefttransform-origin: bottom left;
.origin-lefttransform-origin: left;
.origin-top-lefttransform-origin: top left;

Usage

Specify an element’s transform origin using the origin-{keyword} utilities.

Transform Origin - 图1

  1. <img class="origin-center transform rotate-45 ...">
  2. <img class="origin-top-left transform rotate-45 ...">
  3. <img class="origin-bottom-right transform rotate-45 ...">
  4. <img class="origin-left transform rotate-45 ...">

Responsive

To control the transform-origin of an element at a specific breakpoint, add a {screen}: prefix to any existing transform-origin utility. For example, use md:origin-top to apply the origin-top utility at only medium screen sizes and above.

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Transform Origin - 图2

all

Transform Origin - 图3

sm

Transform Origin - 图4

md

Transform Origin - 图5

lg

Transform Origin - 图6

xl

  1. <img class="origin-center sm:origin-top-left md:origin-top-right lg:origin-bottom-right xl:origin-bottom-left ...">

Transform Origin - 图7

Customizing

Origin values

By default Tailwind provides transform-origin utilities for all of the built-in browser keyword options. You change, add, or remove these by customizing the transformOrigin section of your Tailwind theme config.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. transformOrigin: {
  6. + '24': '6rem',
  7. + 'full': '100%',
  8. }
  9. }
  10. }
  11. }

Learn more about customizing the default theme in the theme customization documentation.

Responsive and pseudo-class variants

By default, only responsive variants are generated for transform-origin utilities.

You can control which variants are generated for the transform-origin utilities by modifying the transformOrigin property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - transformOrigin: ['responsive'],
  6. + transformOrigin: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

If you don’t plan to use the transform-origin utilities in your project, you can disable them entirely by setting the transformOrigin property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + transformOrigin: false,
  6. }
  7. }

← Skew   Appearance →