1. 效果
  2. 盒阴影

Quick reference

属性
shadow-smbox-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
shadowbox-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
shadow-mdbox-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
shadow-lgbox-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
shadow-xlbox-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
shadow-2xlbox-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
shadow-innerbox-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
shadow-nonebox-shadow: 0 0 #0000;

基本用法(Basic usage)

添加外部阴影(Adding an outer shadow)

使用 shadow-smshadowshadow-mdshadow-lgshadow-xlshadow-2xl 工具将不同大小的外部盒子阴影应用于元素。

🌐 Use the shadow-sm, shadow, shadow-md, shadow-lg, shadow-xl, or shadow-2xl utilities to apply different sized outer box shadows to an element.

shadow-md

shadow-lg

shadow-xl

shadow-2xl

<div class="shadow-md ..."></div>
<div class="shadow-lg ..."></div>
<div class="shadow-xl ..."></div>
<div class="shadow-2xl ..."></div>

添加内阴影(Adding an inner shadow)

使用 shadow-inner 工具为元素应用细微的内阴影。这对于表单控件或面板等元素很有用。

🌐 Use the shadow-inner utility to apply a subtle inset box shadow to an element. This can be useful for things like form controls or wells.

shadow-inner

<div class="shadow-inner ..."></div>

去除阴影(Removing the shadow)

使用 shadow-none 可以移除元素上已有的阴影。这通常用于移除在较小屏幕断点下应用的阴影。

🌐 Use shadow-none to remove an existing box shadow from an element. This is most commonly used to remove a shadow that was applied at a smaller breakpoint.

shadow-none

<div class="shadow-none ..."></div>

有条件申请

悬停、聚焦及其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:shadow-lg 仅在 hover 时应用 shadow-lg 工具。

<div class="shadow hover:shadow-lg">
  <!-- ... -->
</div>

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:shadow-lg 仅在中等屏幕尺寸及以上时应用 shadow-lg 工具。

<div class="shadow md:shadow-lg">
  <!-- ... -->
</div>

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。


使用自定义值(Using custom values)

自定义主题(Customizing your theme)

默认情况下,Tailwind 提供六种投影工具、一个内阴影工具以及一个用于移除现有阴影的工具。你可以通过编辑 theme.boxShadowtheme.extend.boxShadow 在你的 tailwind.config.js 文件中自定义这些值。

🌐 By default, Tailwind provides six drop shadow utilities, one inner shadow utility, and a utility for removing existing shadows. You can customize these values by editing theme.boxShadow or theme.extend.boxShadow in your tailwind.config.js file.

如果提供了 DEFAULT 阴影,它将用于无后缀的 shadow 工具。任何其他键将用作后缀,例如键 '2' 将创建相应的 shadow-2 工具。

🌐 If a DEFAULT shadow is provided, it will be used for the non-suffixed shadow utility. Any other keys will be used as suffixes, for example the key '2' will create a corresponding shadow-2 utility.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      boxShadow: {
        '3xl': '0 35px 60px -15px rgba(0, 0, 0, 0.3)',
      }
    }
  }
}

主题自定义文档中了解有关自定义默认主题的更多信息。

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

任意值(Arbitrary values)

如果你需要使用一次性的 box-shadow 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。

<div class="shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
  <!-- ... -->
</div>

任意值 文档中了解有关任意值支持的更多信息。