
布局
用于控制元素纵横比的工具。
使用 aspect-* 工具来设置元素所需的纵横比。
🌐 Use the aspect-* utilities to set the desired aspect ratio of an element.
<iframe class="w-full aspect-video ..." src="https://www.youtube.com/..."></iframe>
Tailwind 默认没有包含大量的宽高比值,因为直接使用任意值更简单。更多信息请参阅任意值部分。
🌐 Tailwind doesn’t include a large set of aspect ratio values out of the box since it’s easier to just use arbitrary values. See the arbitrary values section for more information.
aspect-* 工具使用了原生 aspect-ratio CSS 属性,而 Safari 在 15 版本之前不支持该属性。在 Safari 15 尚未普及之前,Tailwind 的 aspect-ratio 插件是一个很好的替代方案。
🌐 The aspect-* utilities use the native aspect-ratio CSS property, which was not supported in Safari until version 15. Until Safari 15 is popularized, Tailwind’s aspect-ratio plugin is a good alternative.
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:aspect-square 仅在 hover 时应用 aspect-square 工具。
<iframe class="w-full aspect-video hover:aspect-square" src="https://www.youtube.com/..."></iframe>有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:aspect-square 仅在中等屏幕尺寸及以上时应用 aspect-square 工具。
<iframe class="w-full aspect-video md:aspect-square" src="https://www.youtube.com/..."></iframe>要了解更多信息,请查看有关 响应式设计、暗黑模式、以及 其他媒体查询修饰符 的文档。
默认情况下,Tailwind 提供了一组最小的 aspect-ratio 工具。你可以通过编辑 tailwind.config.js 文件中的 theme.aspectRatio 或 theme.extend.aspectRatio 来自定义这些值。
🌐 By default, Tailwind provides a minimal set of aspect-ratio utilities. You can customize these values by editing theme.aspectRatio or theme.extend.aspectRatio in your tailwind.config.js file.
module.exports = {
theme: {
extend: {
aspectRatio: {
'4/3': '4 / 3',
},
}
}
}
在主题自定义文档中了解有关自定义默认主题的更多信息。
🌐 Learn more about customizing the default theme in the theme customization documentation.
如果你需要使用一次性的 aspect-ratio 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。
<iframe class="w-full aspect-[4/3]" src="https://www.youtube.com/..."></iframe>在 任意值 文档中了解有关任意值支持的更多信息。