Translate

    v1.2.0+

    Utilities for translating elements with transform.

    Translate an element by first enabling transforms with the utility, then specifying the translate direction and distance using the translate-x-{amount} and translate-y-{amount} utilities.

    Note that because Tailwind implements transforms using CSS custom properties, the transform utilities are not supported in older browsers like IE11. If you need transforms for your project and need to support older browsers, or other custom CSS.

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

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

    Translate - 图2

    sm

    Translate - 图4

    md

    lg

    Translate - 图6

    xl

    1. <img class="transform translate-y-6 sm:-translate-y-6 md:translate-y-2 lg:-translate-y-8 xl:translate-y-0...">

    By default Tailwind provides fixed value translate utilities that match our , as well as 50% and 100% variations for translating relative to the element’s size.

    You can customize the global spacing scale in the theme.spacing or theme.extend.spacing sections of your tailwind.config.js file:

    To customize the translate scale separately, use the theme.translate section of your tailwind.config.js file.

    1. // tailwind.config.js
    2. theme: {
    3. extend: {
    4. translate: {
    5. + '1/7': '14.2857143%',
    6. + '2/7': '28.5714286%',
    7. + '3/7': '42.8571429%',
    8. + '4/7': '57.1428571%',
    9. + '5/7': '71.4285714%',
    10. + '6/7': '85.7142857%',
    11. }
    12. }

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

    By default, only responsive, hover and focus variants are generated for translate utilities.

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

    For example, this config will also generate active and group-hover variants:

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

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