Visibility 可见性
控制元素可见性的实用工具。
| Class | Properties |
|---|
基本用法
使元素不可见
使用 invisible 来隐藏一个元素,但仍然保持其在 DOM 中的位置,影响其他元素的布局(与display文档中的 hidden 进行比较)。
01
02
03
html
<div class="grid grid-cols-3 gap-4">
<div>01</div>
<div class="invisible ...">02</div>
<div>03</div>
</div>折叠元素
使用 collapse 来隐藏表格行、行组、列和列组,就像它们被设置为 display: none 一样,但不影响其他行和列的大小。
这样可以动态切换行和列,而不影响表格布局。
Showing all rows
| Invoice # | Client | Amount |
|---|---|---|
| #100 | Pendant Publishing | $2,000.00 |
| #101 | Kruger Industrial Smoothing | $545.00 |
| #102 | J. Peterman | $10,000.25 |
Hiding a row using
`collapse`| Invoice # | Client | Amount |
|---|---|---|
| #100 | Pendant Publishing | $2,000.00 |
| #101 | Kruger Industrial Smoothing | $545.00 |
| #102 | J. Peterman | $10,000.25 |
Hiding a row using
`hidden`| Invoice # | Client | Amount |
|---|---|---|
| #100 | Pendant Publishing | $2,000.00 |
| #101 | Kruger Industrial Smoothing | $545.00 |
| #102 | J. Peterman | $10,000.25 |
html
<table>
<thead>
<tr>
<th>Invoice #</th>
<th>Client</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>#100</td>
<td>Pendant Publishing</td>
<td>$2,000.00</td>
</tr>
<tr class="collapse">
<td>#101</td>
<td>Kruger Industrial Smoothing</td>
<td>$545.00</td>
</tr>
<tr>
<td>#102</td>
<td>J. Peterman</td>
<td>$10,000.25</td>
</tr>
</tbody>
</table>使元素可见
使用 visible 使元素可见。这在不同屏幕尺寸下撤消 invisible 效用时非常有用。
01
02
03
html
<div class="grid grid-cols-3 gap-4">
<div>01</div>
<div class="visible ...">02</div>
<div>03</div>
</div>有条件地应用
悬停,焦点和其他状态
Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:invisible 只在悬停时应用 invisible 实用程序。
html
<div class="visible hover:invisible">
<!-- ... -->
</div>要查看所有可用状态修饰符的完整列表,请查看悬停,焦点和其他状态文档。
断点和媒体查询
您还可以使用变体修饰符来定位媒体查询,如响应式断点、暗模式、偏好减少动作等。例如,使用 md:invisible 仅在中等屏幕尺寸及以上应用 invisible 实用程序。
html
<div class="visible md:invisible">
<!-- ... -->
</div>