<col> | HTML列属性标签的定义与用法

定义与用法

  • <col> 标签为表格中一个或多个列定义属性值。
  • 如需对全部列应用样式,<col> 标签很有用,这样就不需要对各个单元和各行重复应用样式了。
  • 只能在 table 或 colgroup 元素中使用 <col> 标签。
  • 所有主流浏览器都支持 <col> 标签。

提示:在HTML中,<col>标记不需要结束标记,但是在XHTML中,它需要结束标记</ col>标记。


语法格式

< col span = “” style = “” >


示例代码

<table border="1">  
    <colgroup>  
        <col span="2" style="background-color:#7fffd4">  
        <col span="2" style="background-color:#98f5ff">  
    </colgroup>  
    <tr>  
        <th>学号</th>  
        <th>姓名</th>  
        <th>数学</th>  
        <th>语文</th>  
    </tr>  
    <tr>  
        <td>1</td>  
        <td>刘伟</td>  
         <td>68</td>  
         <td>54</td>  
    </tr>  
    <tr>  
        <td>2</td>  
        <td>赵安</td>  
         <td>65</td>  
         <td>61</td>  
    </tr>  
    <tr>  
        <td>3</td>  
        <td>李梅</td>  
         <td>55</td>  
         <td>78</td>  
    </tr>  
</table>  

效果展示:


标签属性

属性描述
alignleft
right
center
justify
char
HTML5 不支持。规定与 <col> 元素相关的内容的水平对齐方式。
charcharacterHTML5 不支持。规定根据哪个字符来对齐与 <col> 元素相关的内容。
charoffnumberHTML5 不支持。规定第一个对齐字符的偏移量。
spannumber规定 <col> 元素应该横跨的列数。
valigntop
middle
bottom
baseline
HTML5 不支持。规定与 <col> 元素相关的内容的垂直对齐方式。
width%
pixels
relative_length
HTML5 不支持。Specifies the width of a <col> element

全局属性

HTML <col>标签支持HTML中所有的全局属性。


事件属性

HTML <col>标签支持HTML中所有的事件属性。


相关