Order

Utilities for controlling the order of flex items.

Class reference

ClassProperties
.order-firstorder: -1;
.order-lastorder: 999;
.order-noneorder: 0;
.order-1order: 1;
.order-2order: 2;
.order-3order: 3;
.order-4order: 4;
.order-5order: 5;
.order-6order: 6;
.order-7order: 7;
.order-8order: 8;
.order-9order: 9;
.order-10order: 10;
.order-11order: 11;
.order-12order: 12;

Usage

Use .order-{order} to render flex items in a different order than they appear in the DOM.

Order - 图1

  1. <div class="flex">
  2. <div class="order-last">1</div>
  3. <div>2</div>
  4. <div>3</div>
  5. </div>

Responsive

To apply a flex direction utility only at a specific breakpoint, add a {screen}: prefix to the existing class name. For example, adding the class md:flex-row to an element would apply the flex-row utility at medium screen sizes and above.

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

  1. <div class="flex">
  2. <div>1</div>
  3. <div>2</div>
  4. <div class="order-first sm:order-last md:order-none lg:order-first xl:order-last">3</div>
  5. <div>4</div>
  6. <div>5</div>
  7. </div>

Order - 图2

Customizing

By default Tailwind provides utilities for order-first, order-last, order-none, and an order-{number} utility for the numbers 1 through 12. You change, add, or remove these by editing the theme.order section of your tailwind.config.js file.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. order: {
  5. first: '-1',
  6. last: '999',
  7. - none: '0',
  8. + normal: '0',
  9. '1': '1',
  10. '2': '2',
  11. '3': '3',
  12. '4': '4',
  13. '5': '5',
  14. '6': '6',
  15. - '7': '7',
  16. - '8': '8',
  17. - '9': '9',
  18. - '10': '10',
  19. - '11': '11',
  20. - '12': '12',
  21. }
  22. }
  23. }

Responsive and pseudo-class variants

By default, only responsive variants are generated for order utilities.

You can control which variants are generated for the order utilities by modifying the order 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. - order: ['responsive'],
  6. + order: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

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

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