
布局
用于控制浏览器如何计算元素总尺寸的工具。
使用 box-border 工具将元素的 box-sizing 设置为 border-box,告诉浏览器在设置高度或宽度时包括元素的边框和内边距。
🌐 Use the box-border utility to set an element’s box-sizing to border-box, telling the browser to include the element’s borders and padding when you give it a height or width.
这意味着一个100像素×100像素的元素,带有2像素的边框和各边4像素的内边距,将被渲染为100像素×100像素,其中内部内容区域为88像素×88像素。
🌐 This means a 100px × 100px element with a 2px border and 4px of padding on all sides will be rendered as 100px × 100px, with an internal content area of 88px × 88px.
Tailwind 使其成为我们 preflight 基础样式 中所有元素的默认设置。
🌐 Tailwind makes this the default for all elements in our preflight base styles.
<div class="box-border h-32 w-32 p-4 border-4 ...">
<!-- ... -->
</div>
使用 box-content 工具将元素的 box-sizing 设置为 content-box,告诉浏览器在元素指定的宽度或高度之外添加边框和内边距。
🌐 Use the box-content utility to set an element’s box-sizing to content-box, telling the browser to add borders and padding on top of the element’s specified width or height.
这意味着一个 100px × 100px 的元素,带有 2px 的边框和四周 4px 的内边距,实际上将被渲染为 112px × 112px,其内部内容区域为 100px × 100px。
🌐 This means a 100px × 100px element with a 2px border and 4px of padding on all sides will actually be rendered as 112px × 112px, with an internal content area of 100px × 100px.
<div class="box-content h-32 w-32 p-4 border-4 ...">
<!-- ... -->
</div>
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:box-content 仅在 hover 时应用 box-content 工具。
<div class="box-border hover:box-content">
<!-- ... -->
</div>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:box-content 仅在中等屏幕尺寸及以上时应用 box-content 工具。
<div class="box-border md:box-content">
<!-- ... -->
</div>