不推荐使用 html <COL align> 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5261514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is html <COL align> deprecated?
提问by Ian Boyd
i'm looking at the W3Schools demo of using the <COL>
element to align columns:
我正在查看使用<COL>
元素对齐列的W3Schools 演示:
<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></td>
</tr>
</table>
And browser's rendering of it is not encouraging:
浏览器对它的渲染并不令人鼓舞:
Chrome (10.0.648.127):
铬(10.0.648.127):
FireFox (3.6.8):
火狐(3.6.8):
Internet Explorer 9 (standards mode):
Internet Explorer 9(标准模式):
Internet Explorer 8 (standards mode):
Internet Explorer 8(标准模式):
Internet Explorer 7 (standards mode):
Internet Explorer 7(标准模式):
Internet Explorer (quirks mode):
Internet Explorer(怪癖模式):
It's interesting to note that <COL align>
usedto work in browsers, and the feature was taken awayin ie8. (And Chrome, with position of being the arbiter of all things perfect, doesn't support it.)
有趣的是,它<COL align>
曾经在浏览器中工作,而该功能在 ie8 中被取消了。(而 Chrome,作为一切完美的仲裁者,不支持它。)
This makes me wonder if <COL align>
is something that's not supposedto work.
这让我想知道是否<COL align>
是不应该工作的东西。
Has <COL align>
been deprecated?
已<COL align>
弃用?
Update One
更新一
i understand that it hasn't been formally deprecated. But the fact that browsers usedto support it, then stoppedsupporting it makes me believe that there is some historical story that i'm missing. i assume the intentional removal of col align
support from IE, and the continued lack of support from other browsers, indicates something is going on.
我知道它还没有被正式弃用。但是浏览器曾经支持它,然后停止支持它的事实让我相信有一些我遗漏的历史故事。我认为有意取消col align
IE的支持,以及持续缺乏其他浏览器的支持,表明某些事情正在发生。
Update Two
更新二
i was mistakenly assuming lack of support for all features of <COL>
meant <COL>
itself isn't supported. i mistakenly assumed that since the only attribute i was trying wasn't working: that the element wasn't working. This was my mistake; and in hindsight i shouldhave asked if "COL align" is deprecated (which it is).
我错误地认为不支持<COL>
意味着<COL>
本身的所有功能都不受支持。我错误地认为,因为我尝试的唯一属性不起作用:该元素不起作用。这是我的错误;事后看来,我应该问“COL align”是否已被弃用(确实如此)。
In my defense i assumed an example would have been shown what wasn't working "anymore".
在我的辩护中,我假设一个例子会显示什么“不再”起作用。
See also
也可以看看
回答by Domenic
Yes, the align
attribute of <col />
no longer appears in HTML5. Says the spec!
是的,该align
属性<col />
不再出现在 HTML5 中。说规范!
Also, it's worth noting that you can't achieve a similar result using CSS on the <col />
tag. The style
attribute (or induced style from id
, class
, etc.) only takes into account properties that sensibly apply to the column itself. That is, while each <td />
can contain text content and thus can have attributes like text-align
set, the <col />
element does not contain text and thus none of the text-level styles apply. (Block-level stuff like background-color
still works.)
此外,值得注意的是,您无法在<col />
标签上使用 CSS 获得类似的结果。该style
属性(或感应式的id
,class
等等),只考虑到了合理适用于柱本身帐户属性。也就是说,虽然每个元素都<td />
可以包含文本内容,因此可以具有类似text-align
set 的属性,但<col />
元素不包含文本,因此没有任何文本级别的样式适用。(像块级的东西background-color
仍然有效。)
However, in basic cases not involving colspan
or rowspan
, you can select blocks of <td />
s (and thus "columns" in a sense) by using the CSS pseudo-class :nth-of-type
. E.g. to center the third column of the table with class c3
use
但是,在不涉及colspan
or 的基本情况下rowspan
,您可以<td />
使用 CSS 伪类选择s块(因此在某种意义上是“列”):nth-of-type
。例如使用类c3
使用将表格的第三列居中
table.c3 td:nth-of-type(3) { text-align: center; }
Edit by OP:
OP编辑:
From The HTML Standard:
来自HTML 标准:
15 Obsolete features
15.2 Non-conforming featuresThe following attributes are obsolete (though the elements are still part of the language), and must not be used by authors: ...
align on colelements
...Use CSS instead.
15 过时的功能
15.2 不合格的功能以下属性已过时(尽管元素仍然是语言的一部分),作者不得使用: ...
在col元素上对齐
...改用 CSS。
The WHATWG wiki gives some recommended alternatives for various obsolete presentational attributes:
WHATWG wiki 为各种过时的表示属性提供了一些推荐的替代方案:
Attribute CSS equivalent ===================== ===================================== align on col elements 'text-align' on the appropriate td/th
Attribute CSS equivalent ===================== ===================================== align on col elements 'text-align' on the appropriate td/th
回答by bastian
Try
尝试
<!doctype html>
<html>
<head>
<title>Table</title>
<style>
table.foo td:nth-of-type(2) {
font-style: italic;
}
</style>
</head>
<body>
<table class="foo">
<thead>
<tr> <th>first</th> <th>second</th> </tr>
</thead>
<tbody>
<tr> <td>bar</td> <td>baz</td> </tr>
<tr> <td>bim</td> <td>buh</td> </tr>
</tbody>
</table>
</body>
<html>
Which renders as:
其呈现为:
回答by Brad
The <col>
tag is not deprecated.
该<col>
标签不会被弃用。
See: How to use <col> tag correctly and is it supported in all browser?I think this answer clarifies its usage, and explains some of the trouble you are having with it.
请参阅: 如何正确使用 <col> 标签以及是否在所有浏览器中都支持?我认为这个答案澄清了它的用法,并解释了你在使用它时遇到的一些问题。
It is part of XHTML and HTML 5. http://www.tutorialspoint.com/html5/html5_tags.htm
它是 XHTML 和 HTML 5 的一部分。 http://www.tutorialspoint.com/html5/html5_tags.htm
回答by canon
[edit] Uggh, you changed your question to refer specifically to the align property.
[编辑] 呃,你改变了你的问题,专门提到 align 属性。
No, it hasn't been deprecated. Browser support is there but the implementation and extent are varied. The only cross-browser success I've really had in using it has been with setting widths for entire columns.
不,它还没有被弃用。有浏览器支持,但实现和范围各不相同。我在使用它时真正获得的唯一跨浏览器成功是为整个列设置宽度。
Notes from W3:
W3的笔记:
- Firefox, Chrome, and Safari only support the span and width attributes of the colgroup element.
- Only the width attribute [of the col element] works in Firefox (none of the other attributes).
- Firefox、Chrome 和 Safari 仅支持 colgroup 元素的 span 和 width 属性。
- 只有 [col 元素的] 宽度属性在 Firefox 中有效(其他属性均无效)。
回答by Martin Jespersen
No it has not, it is both part of the html4 spec and the html5 spec.
不,它没有,它既是 html4 规范的一部分,又是 html5 规范的一部分。
http://www.w3.org/TR/html401/struct/tables.html#h-11.2.4.2
http://www.w3.org/TR/html401/struct/tables.html#h-11.2.4.2
http://dev.w3.org/html5/markup/col.html
http://dev.w3.org/html5/markup/col.html
回答by Martin Jespersen
According to the second example table in the HTML spec, it's colgroup, despite the lack of colgroup tags.
根据 HTML 规范中的第二个示例表,它是 colgroup,尽管缺少 colgroup 标签。
回答by Adam Beizsley-Pycroft
In the interest of making the markup semantically meaningful have you considered substituting your <col>
tags with <colgroup>
?
在制作标记语义上有意义的你考虑的利益替换您<col>
使用标签<colgroup>
?
<col>
is purely used for styling whereas <colgroup>
can be used to group related columns (Perhaps this is why you intend to align two of them left?) You can then apply CSS to the various colgroups to style them accordingly.
<col>
纯粹用于样式,而<colgroup>
可用于对相关列进行分组(也许这就是您打算将其中两个向左对齐的原因?)然后您可以将 CSS 应用于各种 colgroups 以相应地设置它们的样式。