HTML <th> 標簽的 width 屬性
定義和用法
width 屬性規(guī)定表格的表頭單元格的寬度。
通常,單元格占用的空間就是它顯示內容需要的空間。width 屬性用于為單元格設置預定義的寬度。
實例
兩個帶有預定義寬度的單元格:
<table border="1"> <tr> <thwidth="40%"
>Company in USA</th> <thwidth="60%"
>Address</th> </tr> <tr> <td>Apple, Inc.</td> <td>1 Infinite Loop Cupertino, CA 95014</td> </tr> <tr> <td>Google, Inc.</td> <td>1600 Amphitheatre Parkway Mountain View, CA 94043</td> </tr> </table>
瀏覽器支持
盡管不贊成使用 width 屬性,但是所有瀏覽器都支持它。
兼容性注釋
在 HTML 4.01 中,不贊成使用 th 元素的 width 屬性;在 XHTML 1.0 Strict DTD 中,不支持 th 元素的 width 屬性。
請使用 CSS 代替。
CSS 語法:<th style="width:100px">
在我們的 CSS 教程中,您可以找到更多有關 width 屬性 的細節(jié)。
語法
<th width="value">
屬性值
值 | 描述 |
---|---|
pixels | 以像素計的寬度值(比如 "100px")。 |
percent | 以包含元素百分比計的寬度值(比如 "20%")。 |