我正在查看 使用 < 的 W3Schools 演示/code> 元素来对齐列
:
<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):
FireFox (3.6.8):
Internet Explorer 9(标准模式):
Internet Explorer 8(标准模式):
Internet Explorer 7(标准模式):
Internet Explorer(怪异模式):
有趣的是,
使用了< /strong> 在浏览器中工作,该功能在 ie8 中被取消。 (而 Chrome,作为所有事物完美仲裁者的地位,并不支持它。)
这让我想知道
是否不是应该的 去工作。
是否已被弃用?
更新一 据
我所知,它尚未被正式弃用。但事实上,浏览器曾经支持它,然后停止支持它,这让我相信我错过了一些历史故事。我认为 IE 有意删除了对 colalign 的支持,并且其他浏览器持续缺乏支持,这表明正在发生一些事情。
更新二
我错误地认为缺乏对
所有功能的支持意味着
本身不受支持。我错误地认为,因为我尝试的唯一属性不起作用:该元素不起作用。这是我的错误;事后看来,我应该询问“COLalign”是否已被弃用(事实确实如此)。
在我的辩护中,我假设一个例子会显示什么“不再”起作用。
另请参阅
i'm looking at the 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>
And browser's rendering of it is not encouraging:
Chrome (10.0.648.127):
FireFox (3.6.8):
Internet Explorer 9 (standards mode):
Internet Explorer 8 (standards mode):
Internet Explorer 7 (standards mode):
Internet Explorer (quirks mode):
It's interesting to note that <COL align>
used to work in browsers, and the feature was taken away in ie8. (And Chrome, with position of being the arbiter of all things perfect, doesn't support it.)
This makes me wonder if <COL align>
is something that's not supposed to work.
Has <COL align>
been deprecated?
Update One
i understand that it hasn't been formally deprecated. But the fact that browsers used to support it, then stopped supporting 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.
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 should have asked if "COL align" is deprecated (which it is).
In my defense i assumed an example would have been shown what wasn't working "anymore".
See also
发布评论
评论(6)
是的,
的
align
属性不再出现在 HTML5 中。 规范说明!另外,值得注意的是,在
标记上使用 CSS 无法获得类似的结果。
style
属性(或从id
、class
等诱导的样式)仅考虑合理应用于列本身的属性。也就是说,虽然每个可以包含文本内容,因此可以设置诸如
text-align
之类的属性,但可以包含文本内容。 元素不包含文本,因此没有任何文本级样式适用。 (像
background-color
这样的块级内容仍然有效。)但是,在不涉及
colspan
或rowspan
的基本情况下,您可以选择以下块:通过使用 CSS 伪类:nth-of-type
来实现(以及某种意义上的“列”)。例如,要将表格的第三列与类
c3
居中,请使用Edit by OP:
From HTML 标准:
WHATWG wiki 为各种过时的演示属性提供了一些推荐的替代方案:
Yes, the
align
attribute of<col />
no longer appears in HTML5. Says the spec!Also, it's worth noting that you can't achieve a similar result using CSS on the
<col />
tag. Thestyle
attribute (or induced style fromid
,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 liketext-align
set, the<col />
element does not contain text and thus none of the text-level styles apply. (Block-level stuff likebackground-color
still works.)However, in basic cases not involving
colspan
orrowspan
, 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 classc3
useEdit by OP:
From the HTML Standard:
The WHATWG wiki gives some recommended alternatives for various obsolete presentational attributes:
尝试
呈现为:
Try
Which renders as:
编辑:这回答了原来的问题,该问题过去询问
本身而不是对齐属性。
标签未被弃用。
请参阅:如何使用 < ;科尔>标签正确并且所有浏览器都支持它吗?
我认为这个答案澄清了它的用法,并解释了您遇到的一些问题。
它是 XHTML 和 HTML 5 的一部分。 http://www.tutorialspoint.com/html5/html5_tags .htm
Edit: This answers the original question, which used to ask about
<col>
itself rather than the align attribute.The
<col>
tag is not deprecated.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.
It is part of XHTML and HTML 5. http://www.tutorialspoint.com/html5/html5_tags.htm
为了使标记在语义上有意义,您是否考虑 替换您的
标签带有
吗?
纯粹用于样式设置,而
可用于对相关列进行分组(也许这就是您打算将其中两个列向左对齐的原因?)然后,您可以将 CSS 应用于各种 colgroup 以相应地设置它们的样式。
In the interest of making the markup semantically meaningful have you considered substituting your
<col>
tags with<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.根据 HTML 规范中的第二个示例表,它是 colgroup,尽管缺少 colgroup 标签。
http://www.w3.org/TR/html4 /struct/tables.html#h-11.4.1
According to the second example table in the HTML spec, it’s colgroup, despite the lack of colgroup tags.
http://www.w3.org/TR/html4/struct/tables.html#h-11.4.1
编辑:这回答了原来的问题,该问题过去询问
本身而不是align属性。
不,它没有,它都是 html4 的一部分规范和 html5 规范。
http://www.w3.org/TR/ html401/struct/tables.html#h-11.2.4.2
http:// /dev.w3.org/html5/markup/col.html
http ://www.html-5.com/tags/col-tag/
Edit: This answers the original question, which used to ask about
<col>
itself rather than the align attribute.No it has not, it is both part of the html4 spec and the html5 spec.
http://www.w3.org/TR/html401/struct/tables.html#h-11.2.4.2
http://dev.w3.org/html5/markup/col.html
http://www.html-5.com/tags/col-tag/