html - html <COL align> 是否已弃用?

标签 html col

我正在查看 W3Schools demo of using the <COL> element to align columns :

<table width="100%" border="1">
  <col align="left" />
  <col align="left" />
  <col align="right" />
  <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>

浏览器对它的渲染并不令人鼓舞:

Chrome (10.0.648.127):
enter image description here

火狐 (3.6.8):
enter image description here

Internet Explorer 9(标准模式):
enter image description here

Internet Explorer 8(标准模式):
enter image description here

Internet Explorer 7(标准模式):
enter image description here

Internet Explorer(怪癖模式): enter image description here

有趣的是 <COL align> 曾经在浏览器中工作,而该功能在 ie8 中被拿走了。 (而 Chrome,作为所有事物完美的仲裁者,不支持它。)

这让我想知道是否 <COL align>不是应该起作用的东西。

<COL align>已弃用?


更新一

我知道它还没有被正式弃用。但事实上浏览器曾经支持它,然后停止支持它,这让我相信我遗漏了一些历史故事。我假设有意删除 col align来自 IE 的支持,以及其他浏览器的持续缺乏支持,表明正在发生某些事情。

更新二

我错误地假设不支持 <COL> 的所有功能意味着<COL>本身不受支持。我错误地认为,因为我尝试的唯一属性不起作用:元素不起作用。这是我的错误;事后看来,我应该问过“COL align”是否被弃用(确实如此)。

在我的辩护中,我假设一个例子会显示什么“不再”起作用了。

另见

最佳答案

是的,align <col /> 的属性不再出现在 HTML5 中。 Says the spec!

此外,值得注意的是,您无法在 <col /> 上使用 CSS 获得类似的结果。标签。 style属性(或来自 idclass 等的样式)仅考虑适用于列本身的属性。也就是说,虽然每个 <td />可以包含文本内容,因此可以具有类似 text-align 的属性设置,<col />元素不包含文本,因此没有任何文本级样式适用。 (像 background-color 这样的 block 级别的东西仍然有效。)

但是,在基本情况下不涉及colspanrowspan , 您可以选择 <td /> 的 block s(因此在某种意义上是“列”)通过使用 CSS 伪类 :nth-of-type .例如。以类 c3 居中表格的第三列使用

table.c3 td:nth-of-type(3) { text-align: center; }

由 OP 编辑​​:

来自 The HTML Standard :

15 Obsolete features
15.2 Non-conforming features

The following attributes are obsolete (though the elements are still part of the language), and must not be used by authors: ...
align on col elements
...

   Use CSS instead.

WHATWG wiki 为各种过时的 presentational attributes 提供了一些推荐的替代方案:

Attribute              CSS equivalent
=====================  =====================================
align on col elements  'text-align' on the appropriate td/th

关于html - html <COL align> 是否已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5261514/

相关文章:

java - 如何使用 Spark 更改所有数据集中的非数值?

html - 自动转到另一个站点

html - 简单的 css 无法在运行中加载

html - 如何将图片放在网页的最左边和中间

javascript - 点击向上滑动div

javascript - 将 cURL HTML 数据提供给 AngularJs

r - 在散点图中以不同的方式着色/填充一点

python - 搜索 csv 文件中的列

css - 在超大屏幕中并排放置三张背景照片