Top / Right / Bottom / Left

    Use the utilities to anchor absolutely positioned elements against any of the edges of the nearest positioned parent.

    Combined with Tailwind’s padding and margin utilities, you’ll probably find that these are all you need to precisely control absolutely positioned elements.

    To position an element only at a specific breakpoint, add a {screen}: prefix to any existing positioning utility. For example, adding the class md:inset-y-0 to an element would apply the inset-y-0 utility at medium screen sizes and above.

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

    Top / Right / Bottom / Left - 图2

    all

    sm

    md

    Top / Right / Bottom / Left - 图5

    lg

    xl

    1. <div class="absolute inset-0 sm:bottom-0 sm:left-0 md:top-0 md:inset-x-0 lg:right-0 lg:inset-y-0 xl:bottom-0 xl:inset-x-0"></div>
    2. </div>

    By default Tailwind only provides 0 and auto top/right/bottom/left/inset utilities. You can change, add, or remove these by editing the theme.inset section of your tailwind.config.js file.

    If you’d like to add any negative top/right/bottom/left classes that take the same form as Tailwind’s classes, prefix the keys in your config file with a dash:

    1. // tailwind.config.js
    2. theme: {
    3. extend: {
    4. inset: {
    5. + '-16': '-4rem',
    6. }
    7. }
    8. }

    Tailwind is smart enough to generate classes like -top-16 when it sees the leading dash, not top--16 like you might expect.

    By default, only responsive variants are generated for top, right, bottom, left, and inset utilities.

    You can control which variants are generated for the top, right, bottom, left, and inset utilities by modifying the inset property in the section of your tailwind.config.js file.

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

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

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