试一试
caption-side: top;
caption-side: bottom;
<section class="default-example" id="default-example">
<table class="transition-all" id="example-element">
<caption>
Famous animals
</caption>
<tr>
<th>Name</th>
<th>Location</th>
</tr>
<tr>
<td>Giraffe</td>
<td>Africa</td>
</tr>
<tr>
<td>Penguin</td>
<td>Antarctica</td>
</tr>
<tr>
<td>Sloth</td>
<td>South America</td>
</tr>
<tr>
<td>Tiger</td>
<td>Asia</td>
</tr>
</table>
</section>
table {
font-size: 1.2rem;
text-align: left;
color: black;
}
th,
td {
padding: 0.2rem 1rem;
}
caption {
background: #ffcc33;
padding: 0.5rem 1rem;
}
tr {
background: #eeeeee;
}
tr:nth-child(even) {
background: #cccccc;
}
语法
css
/* Directional values */
caption-side: top;
caption-side: bottom;
/* Global values */
caption-side: inherit;
caption-side: initial;
caption-side: revert;
caption-side: revert-layer;
caption-side: unset;
caption-side 属性被指定为下面列出的一个关键词值。
值
注意:CSS 逻辑属性和值模块定义了两个逻辑值,inline-start 和 inline-end,分别用于将标题框定位在表格的内联起始边缘和内联结束边缘。这些值在任何浏览器中都不受支持。
正式定义
正式语法
caption-side =
top |
bottom
示例
设置上下标题
HTML
html
<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>
CSS
css
.top caption {
caption-side: top;
}
.bottom caption {
caption-side: bottom;
}
table {
border: 1px solid red;
}
td {
border: 1px solid blue;
}
结果
规范
| 规范 |
|---|
| 层叠样式表级别 2 # propdef-caption-side |
| CSS 逻辑属性和值第 1 级 # caption-side |
浏览器兼容性
加载中…