gpt4 book ai didi

html - 为什么 colgroup/col 在 Chrome 中不起作用

转载 作者:太空狗 更新时间:2023-10-29 16:37:29 25 4
gpt4 key购买 nike

my previous question 的答案之一说明 colgroup/col 只能在 IE 中工作。

我写了一个适用于 IE9 的示例(见下文)(单元格内容位于第 3 列的中心),但不适用于最新版本的 Chrome。

我做错了什么?

HTML 示例:

<html>
<head><title>test table centerring</title></head>
<body>

<table border="1">
<colgroup>
<col/>
<col/>
<col align="center">
</colgroup>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Name 1</td>
<td>Value 1</td>
</tr>
<tr>
<td>2</td>
<td>Name 2, Name 2, Name 2, Name 2</td>
<td>Value 2</td>
</tr>
<tr>
<td>3</td>
<td>Name 3</td>
<td>Value 3</td>
</tr>
<tr>
<td>4</td>
<td>Name 4</td>
<td>Value 4, Value 4, Value 4, Value 4</td>
</tr>
</tbody>
</table>

</body></html>

最佳答案

实际上,我很确定只有 IE 支持它,但对问题 Is there any way to center certain columns in table? 的一个答案感到困惑.答案的作者还指出了一些限制: http://www.quirksmode.org/css/columns.html

Unfortunately table columns are quite hard to use, because if you use them you essentially have a table that's subdivided in two ways: by rows and by columns. The general rule is that any style defined on a row overrules any style defined on a column.

Secondly, W3C specifies that only a few declarations may be used on columns: border, background, width and visibility. Exception: IE7 and lower allow all declarations.

Thirdly, there's some confusion whether the column styles are applied to the column as a whole, or to the individual <td>s contained by it. The border declaration seems to be applied to the column as a whole, but width is applied to the individual cells.

这使得 colgroup/col 对于居中几乎毫无用处。

关于html - 为什么 colgroup/col 在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10289494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com