Top / Right / Bottom / Left

    Utilities for controlling the placement of positioned elements.

    Show all classes

    Use the utilities to set the horizontal or vertical position of a .

    Using negative values

    To use a negative top/right/bottom/left value, prefix the class name with a dash to convert it to a negative value.

    Top / Right / Bottom / Left - 图2

    1. <div class="relative h-32 w-32 ...">
    2. <div class="absolute h-14 w-14 -left-4 -top-4 ..."></div>
    3. </div>

    For more control, you can also use the LTR and RTL modifiers to conditionally apply specific styles depending on the current text direction.


    Hover, focus, and other states

    Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:top-6 to only apply the top-6 utility on hover.

    1. <div class="top-4 hover:top-6">
    2. <!-- ... -->

    For a complete list of all available state modifiers, check out the documentation.

    You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:top-6 to apply the top-6 utility at only medium screen sizes and above.

    To learn more, check out the documentation on , Dark Mode and .


    Customizing your theme

    You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

    tailwind.config.js

    1. module.exports = {
    2. theme: {
    3. spacing: {
    4. }
    5. }
    6. }
    7. }

    Alternatively, you can customize just the top/right/bottom/left/inset scale by editing theme.inset or theme.extend.inset in your tailwind.config.js file.

    tailwind.config.js

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

    If you need to use a one-off top/right/bottom/left value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

    1. <div class="top-[3px]">
    2. <!-- ... -->
    3. </div>