我们能够经由过程设置css caption-side属性的相干属性值来指定表格(<table>)题目(caption标签)的位置,即:能够运用caption-side属性来指定了题目位于表格的哪一侧。
在table表格中,caption标签是用于为表格供应简短的题目,如题目或简短形貌。caption标签是插在最先<table>标记以后,应当始终是表的第一个子项。然后我们就能够运用caption-side属性变动其在表中的位置了。
我们能够运用caption-side属性,来在表的上方或下方定位表格题目,指定题目位于表格的上方或下方。
注:
1、在CSS 2.1之前,供应了两个值:"left"和"right"来分别将题目定位在表的左侧和右侧。但这两个值在终究的2.1范例中被移除,而且如今已不是规范了,不怎么被浏览器兼容。
2、假如想要在题目框中让题目内容“程度对齐”,须要运用text-align属性;经由过程text-align属性还能够设置别的对齐体式格局。
下面我们来看看caption-side属性是怎样设置table表格的题目位置的。
caption-side属性的基础语法:
caption-side: top | bottom | inherit
默许属性:top
适用于: 'table-caption'元素中
动画:没有
caption-side属性值申明:
top:能够将题目定位在表格上方。
bottom:能够将题目定位在表格下方。
inherit :从父级的题目位置继续题目位置。
caption-side属性的示例:
1、题目在表格上方
html代码:
<table class="default"> <caption><em>表的题目,位置:顶部(默许)</em></caption> <thead> <tr> <th>题目内容 1</th> <th>题目内容 2</th> </tr> </thead> <tfoot> <tr> <td>页脚内容 1</td> <td>页脚内容 2</td> </tr> </tfoot> <tbody> <tr> <td>主体内容 1</td> <td>主体内容 2</td> </tr> </tbody> </table>
css代码:
caption { caption-side: top; padding: .5em; color: #de64a4; }
效果图:
2、题目在表格下方
HTML代码:
<table> <caption><em>表的题目,位置:底部</em></caption> <thead> <tr> <th>题目内容 1</th> <th>题目内容 2</th> </tr> </thead> <tfoot> <tr> <td>页脚内容 1</td> <td>页脚内容 2</td> </tr> </tfoot> <tbody> <tr> <td>主体内容 1</td> <td>主体内容 2</td> </tr> </tbody> </table>
css代码:
caption { caption-side: bottom; padding: .5em; color: #de64a4; }
效果图:
浏览器支撑度:
一切主流浏览器都支撑caption-side属性,比方:Chrome,Firefox,Safari,Opera,Internet Explorer 8+以及Android和iOS
注重:
1、IE8只要指定!DOCTYPE才支撑caption-side属性。
2、在Firefox中支撑left和right这两种非规范值。
总结:以上就是本篇文的全部内容,愿望能对人人的进修有所协助。
以上就是css怎样设置表格题目(caption标签)的位置的细致内容,更多请关注ki4网别的相干文章!
上一篇:php shuffle函数怎样用【php问题】,php shuffle
下一篇:php count函数怎样用【php问题】,php count
支付宝扫一扫打赏
微信扫一扫打赏
共 0 条评论关于"css怎样设置表格题目(caption标签)的位置【css教程】,css,表格标题,caption-side属性"
最新评论