返回介绍

Gap

发布于 2024-07-30 22:16:07 字数 47127 浏览 0 评论 0 收藏 0

Utilities for controlling gutters between grid and flexbox items.

Quick reference

ClassProperties
gap-0gap: 0px;
gap-x-0column-gap: 0px;
gap-y-0row-gap: 0px;
gap-pxgap: 1px;
gap-x-pxcolumn-gap: 1px;
gap-y-pxrow-gap: 1px;
gap-0.5gap: 0.125rem; /* 2px */
gap-x-0.5column-gap: 0.125rem; /* 2px */
gap-y-0.5row-gap: 0.125rem; /* 2px */
gap-1gap: 0.25rem; /* 4px */
gap-x-1column-gap: 0.25rem; /* 4px */
gap-y-1row-gap: 0.25rem; /* 4px */
gap-1.5gap: 0.375rem; /* 6px */
gap-x-1.5column-gap: 0.375rem; /* 6px */
gap-y-1.5row-gap: 0.375rem; /* 6px */
gap-2gap: 0.5rem; /* 8px */
gap-x-2column-gap: 0.5rem; /* 8px */
gap-y-2row-gap: 0.5rem; /* 8px */
gap-2.5gap: 0.625rem; /* 10px */
gap-x-2.5column-gap: 0.625rem; /* 10px */
gap-y-2.5row-gap: 0.625rem; /* 10px */
gap-3gap: 0.75rem; /* 12px */
gap-x-3column-gap: 0.75rem; /* 12px */
gap-y-3row-gap: 0.75rem; /* 12px */
gap-3.5gap: 0.875rem; /* 14px */
gap-x-3.5column-gap: 0.875rem; /* 14px */
gap-y-3.5row-gap: 0.875rem; /* 14px */
gap-4gap: 1rem; /* 16px */
gap-x-4column-gap: 1rem; /* 16px */
gap-y-4row-gap: 1rem; /* 16px */
gap-5gap: 1.25rem; /* 20px */
gap-x-5column-gap: 1.25rem; /* 20px */
gap-y-5row-gap: 1.25rem; /* 20px */
gap-6gap: 1.5rem; /* 24px */
gap-x-6column-gap: 1.5rem; /* 24px */
gap-y-6row-gap: 1.5rem; /* 24px */
gap-7gap: 1.75rem; /* 28px */
gap-x-7column-gap: 1.75rem; /* 28px */
gap-y-7row-gap: 1.75rem; /* 28px */
gap-8gap: 2rem; /* 32px */
gap-x-8column-gap: 2rem; /* 32px */
gap-y-8row-gap: 2rem; /* 32px */
gap-9gap: 2.25rem; /* 36px */
gap-x-9column-gap: 2.25rem; /* 36px */
gap-y-9row-gap: 2.25rem; /* 36px */
gap-10gap: 2.5rem; /* 40px */
gap-x-10column-gap: 2.5rem; /* 40px */
gap-y-10row-gap: 2.5rem; /* 40px */
gap-11gap: 2.75rem; /* 44px */
gap-x-11column-gap: 2.75rem; /* 44px */
gap-y-11row-gap: 2.75rem; /* 44px */
gap-12gap: 3rem; /* 48px */
gap-x-12column-gap: 3rem; /* 48px */
gap-y-12row-gap: 3rem; /* 48px */
gap-14gap: 3.5rem; /* 56px */
gap-x-14column-gap: 3.5rem; /* 56px */
gap-y-14row-gap: 3.5rem; /* 56px */
gap-16gap: 4rem; /* 64px */
gap-x-16column-gap: 4rem; /* 64px */
gap-y-16row-gap: 4rem; /* 64px */
gap-20gap: 5rem; /* 80px */
gap-x-20column-gap: 5rem; /* 80px */
gap-y-20row-gap: 5rem; /* 80px */
gap-24gap: 6rem; /* 96px */
gap-x-24column-gap: 6rem; /* 96px */
gap-y-24row-gap: 6rem; /* 96px */
gap-28gap: 7rem; /* 112px */
gap-x-28column-gap: 7rem; /* 112px */
gap-y-28row-gap: 7rem; /* 112px */
gap-32gap: 8rem; /* 128px */
gap-x-32column-gap: 8rem; /* 128px */
gap-y-32row-gap: 8rem; /* 128px */
gap-36gap: 9rem; /* 144px */
gap-x-36column-gap: 9rem; /* 144px */
gap-y-36row-gap: 9rem; /* 144px */
gap-40gap: 10rem; /* 160px */
gap-x-40column-gap: 10rem; /* 160px */
gap-y-40row-gap: 10rem; /* 160px */
gap-44gap: 11rem; /* 176px */
gap-x-44column-gap: 11rem; /* 176px */
gap-y-44row-gap: 11rem; /* 176px */
gap-48gap: 12rem; /* 192px */
gap-x-48column-gap: 12rem; /* 192px */
gap-y-48row-gap: 12rem; /* 192px */
gap-52gap: 13rem; /* 208px */
gap-x-52column-gap: 13rem; /* 208px */
gap-y-52row-gap: 13rem; /* 208px */
gap-56gap: 14rem; /* 224px */
gap-x-56column-gap: 14rem; /* 224px */
gap-y-56row-gap: 14rem; /* 224px */
gap-60gap: 15rem; /* 240px */
gap-x-60column-gap: 15rem; /* 240px */
gap-y-60row-gap: 15rem; /* 240px */
gap-64gap: 16rem; /* 256px */
gap-x-64column-gap: 16rem; /* 256px */
gap-y-64row-gap: 16rem; /* 256px */
gap-72gap: 18rem; /* 288px */
gap-x-72column-gap: 18rem; /* 288px */
gap-y-72row-gap: 18rem; /* 288px */
gap-80gap: 20rem; /* 320px */
gap-x-80column-gap: 20rem; /* 320px */
gap-y-80row-gap: 20rem; /* 320px */
gap-96gap: 24rem; /* 384px */
gap-x-96column-gap: 24rem; /* 384px */
gap-y-96row-gap: 24rem; /* 384px */

Basic usage

Setting the gap between elements

Use the gap-* utilities to change the gap between both rows and columns in grid and flexbox layouts.

01 02 03 04
<div class="grid gap-4 grid-cols-2">
  <div>01</div>
  <div>02</div>
  <div>03</div>
  <div>04</div>
</div>

Changing row and column gaps independently

Use the gap-x-* and gap-y-* utilities to change the gap between columns and rows independently.

01 02 03 04 05 06
<div class="grid gap-x-8 gap-y-4 grid-cols-3">
  <div>01</div>
  <div>02</div>
  <div>03</div>
  <div>04</div>
  <div>05</div>
  <div>06</div>
</div>

Applying conditionally

Hover, focus, and other states

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

<div class="grid gap-4 hover:gap-6">
  <!-- ... -->
</div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

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

<div class="grid gap-4 md:gap-6">
  <!-- ... -->
</div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind’s gap scale uses the default spacing scale. You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        '11': '2.75rem',
      }
    }
  }
}

Alternatively, you can customize just the gap scale by editing theme.gap or theme.extend.gap in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      gap: {
        '11': '2.75rem',
      }
    }
  }
}

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

Arbitrary values

If you need to use a one-off gap 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.

<div class="grid gap-[2.75rem]">
  <!-- ... -->
</div>

Learn more about arbitrary value support in the arbitrary values documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文