English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML 参考手册

HTML 标签大全

HTML: <col> width 属性

width属性指定 <col>元素的宽度, <col>元素占用显示内容所需的空间。width属性用于设置 <col>元素的预定义宽度,此属性将覆盖 <colgroup>元素中设置的任何宽度。

 HTML <col> tag

在线示例

两个具有预定义宽度的<col>元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML <col> width 属性使用-基础教程(oldtoolbag.com)/title>
<style>table, th, td { border: 1px solid black;}/style>
</head>
<body>
<table>
  <col width="130">
  <col width="80">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
</body>
</html>
Test it out ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the width attribute, but no browser supports relative_length Value.

Definition and Usage

HTML5 The <col> width attribute is no longer supported.

The width attribute specifies the width of the <col> element.

Generally, the <col> element occupies the space required for the displayed content. The width attribute is used to set the predefined width of the <col> element.

Note: This attribute overrides any width set in the <colgroup> element.

Syntax

<col width="pixels|%|relative_length">

Attribute Value

ValueDescription
pixelsSet the width value in pixels (example: width="50").
percentSet the width value as a percentage of the element's enclosing percentage (example: width="50%").
relative_lengthAllocate available pixels to each section.
 HTML <col> tag