导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML 参考手册

HTML 元素(功能排序) HTML 浏览器支持 HTML 属性 HTML 全局属性 HTML 事件 HTML 颜色 HTML 画布 HTML 音频/视频 HTML 字符集 HTML 文档类型 HTML URL 编码 HTML 语言代码 HTML 国家代码 HTTP 状态消息 HTTP 请求方法 PX-EM 转换 键盘快捷键

HTML 标签

<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <col> 标签


实例

使用<colgroup> 和<col> 标记设置三列的背景色:

<table>
 <colgroup>
   <col span="2" style="background-color:red">
   <col style="background-color:yellow">
 </colgroup>
 <tr>
   <th>ISBN</th>
   <th>Title</th>
   <th>Price</th>
 </tr>
 <tr>
   <td>3476896</td>
   <td>My first HTML</td>
   <td>$53</td>
 </tr>
</table>
亲自试一试 »

下面有更多实例。


定义和用法

<col> 标签为表格中一个或多个列定义属性值。

如需对全部列应用样式,<col> 标签很有用,这样就不需要对各个单元和各行重复应用样式了。

您只能在 table 或 <colgroup> 元素中使用 <col> 标签。


提示和注释:

提示: 请为<col> 标签添加 class 属性。这样就可以使用 CSS 来负责对齐方式、宽度和颜色等等。

提示: 如果您希望在 colgroup 内部为每个列规定不同的属性值时,请使用此元素。如果没有 col 元素,列会从 colgroup 那里继承所有的属性值。

注释: col 元素是仅包含属性的空元素。如需创建列,您就必须在 tr 元素内部规定 td 元素。

参见:<colgroup> 标签


浏览器支持

元素          
<col> Yes Yes Yes Yes Yes

属性

属性 描述
span number 规定 col 元素应该横跨的列数。

全局属性

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


事件属性

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


更多实例

实例

对齐表格列中的文本(使用CSS):

<table style="width:100%">
 <tr>
       <th>ISBN</th>
   <th>Title</th>
       <th>Price</th>
 </tr>
 <tr>
       <td>3476896</td>
   <td>My first HTML</td>
       <td style="text-align:right">$53</td>
 </tr>
 <tr>
       <td>2489604</td>
   <td>My first CSS</td>
       <td style="text-align:right">$47</td>
 </tr>
</table>
亲自试一试 »

实例

表格列中的垂直对齐文本(使用CSS):

<table style="height:200px">
 <tr>
       <th>Month</th>
   <th     style="vertical-align:bottom">Savings</th>
 </tr>
 <tr>
       <td>January</td>
   <td     style="vertical-align:bottom">$100</td>
 </tr>
</table>
亲自试一试 »

实例

指定表格列的宽度(使用CSS):

<table>
 <tr>
   <th     style="width:130px">Month</th>
   <th     style="width:80px">Savings</th>
 </tr>
 <tr>
       <td>January</td>
   <td>$100</td>
 </tr>
     <tr>
   <td>February</td>
       <td>$80</td>
 </tr>
</table>
亲自试一试 »

相关页面

HTML DOM 参考手册: Column 对象


默认CSS设置

大多数浏览器将使用以下默认值显示 <col> 元素:

实例

col { 
  display: table-column;
} 
亲自试一试 »

Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。