--- title: caption-side slug: Web/CSS/caption-side tags: - CSS - CSS 属性 - table - 参考 - 表格 translation_of: Web/CSS/caption-side ---
CSS 中 caption-side 属性会将表格的标题{{HTMLElement("caption")}} 放到规定的位置。但是具体显示的位置与表格的 {{cssxref('writing-mode')}} 属性值有关。
caption-side 属性的取值必须是下面所列值中的一个。
/* Directional values */ caption-side: top; caption-side: bottom; /* Warning: non-standard values */ caption-side: left; caption-side: right; caption-side: top-outside; caption-side: bottom-outside; /* Global values */ caption-side: inherit; caption-side: initial; caption-side: unset;
topbottomleft {{non-standard_inline}}right {{non-standard_inline}}top-outside {{non-standard_inline}}top 值产生的效果有不同的定义,在未来可能会重新定义这个值产生的影响效果。bottom-outside {{non-standard_inline}}top 值产生的效果有不同的定义,在未来可能会重新定义这个值产生的影响效果。<table class="top">
<caption>Caption ABOVE the table</caption>
<tr>
<td>Some data</td>
<td>Some more data</td>
</tr>
</table>
<br>
<table class="bottom">
<caption>Caption BELOW the table</caption>
<tr>
<td>Some data</td>
<td>Some more data</td>
</tr>
</table>
.top caption {
caption-side: top;
}
.bottom caption {
caption-side: bottom;
}
table {
border: 1px solid red;
}
td {
border: 1px solid blue;
}
{{EmbedLiveSample('Example', 'auto', 160)}}
| 规范 | 状态 | 描述 |
|---|---|---|
| {{ SpecName('CSS Logical Properties', '#caption-side', 'caption-side') }} | {{ Spec2('CSS Logical Properties') }} |
定义和css定义的书写模式值相关的顶部及底部的值。 |
| {{ SpecName('CSS2.1', 'tables.html#caption-position', 'caption-side') }} | {{ Spec2('CSS2.1') }} | 初始版本。 |
{{Compat("css.properties.caption-side")}}