HTML语言如何一次实现表格整列的对齐方式

来源:互联网 发布:网络名誉权侵权案例 编辑:程序博客网 时间:2024/04/27 21:04

HTML元素 - colGroup
定义
说明表格中一列或一组列的缺省属性。

Specifies property defaults for a column or group of columns in a table.

注释
嵌套的 COL 属性将覆盖 COLGROUP 属性。

使用 SPAN 属性可以指定 COLGROUP 定义的表格列数。该属性的缺省值为 1。

COL 元素可以出现在 COLGROUP 元素之外,这两个元素可用于类似的目的 。但是,你必须使用 COLGROUP 元素来决定表格内部分隔线(rules)应该处于的位置。见下面第一个例子。

若在 COLGROUP 中嵌套了 COL 元素则应该避免在 COLGROUP 中使用 SPAN 标签属性。这是因为属于嵌套的 COL 元素的 SPAN 标签属性将覆盖 COLGROUP 元素中的标签属性。这可能引起代码的混乱及可能并非所愿的结果。参见下面的第二个例子。

TABLE 对象及其关联元素有一个独立的表格对象模型,该模式使用不同于常规对象模型的方法 。要获得关于表格对象模型更多的信息,请参看如何动态生成表格。

此元素在 Internet Explorer 3.0 及以上版本的 HTML 中可用,在 Internet Explorer 4.0 及以上版本的脚本中可用。

此元素是块元素 。

此元素是块元素。COLGROUP 属性。 COLGROUP 元素之外,这两个元素可用于类似的目的。

此元素需要关闭标签 。

示例代码
下面的例子使用了 COLGROUP 元素指定表格中两组列的特征。

This example uses the COLGROUP element to assign specific characteristics to two groups of columns in a table.

<HTML>

<BODY>

<TABLE BORDER="2" RULES="groups">

<!-- RULES is set to "groups", which places internal dividing lines around

table columns defined by COLGROUP . -->

<COLGROUP SPAN="2" STYLE="color:red">

</COLGROUP>

<COLGROUP STYLE="color:blue">

</COLGROUP>

<TR>

<TD>This column is in the first group.</TD>

<TD>This column is in the first group.</TD >

<TD>This column is in the second group.</TD>

</TR>

<TR>

<TD>This column is in the first group.</TD>

<TD>This column is in the first group.</TD>

<TD>This column is in the second group.</TD>

</TR>

</TABLE>

</BODY>

</HTML>

若在 COLGROUP 中嵌套了 COL 元素,COL 元素的标签属性将覆盖 COLGROUP 元素的标签属性。下面的例子演示了这一点。

When COL elements are nested inside a COLGROUP element, the attributes of the COL elements override the attributes of the COLGROUP element. This is demonstrated in the following example.

<HTML>

<BODY>

<TABLE BORDER="2">

<COLGROUP SPAN="3" STYLE="color:green;background:black ">

<! -- Styling is applied to only the first two columns, instead of all

three, and the font color is red instead of green. This is consistant

with the attributes of the COL element. -->

<COL SPAN="2 " STYLE="color:red">

</COLGROUP>

<TR>

<TD>This column is in the first group.</TD>

<TD>This column is in the first group.</TD>

<TD>This column is in the second group .</TD>

</TR>

<TR>

<TD>This column is in the first group.</TD>

<TD>This column is in the first group.</TD>

<TD>This column is in the second group.</TD>

</TR>

</TABLE>

</BODY>

</HTML>

另见 COL 元素则应该避免在 COLGROUP 中使用?

另见

原创粉丝点击