HTML

1个成员

HTML元素 - colGroup

发表于 2017-02-12 4562 次查看

定义

说明表格中一列或一组列的缺省属性。

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 及以上版本的脚本中可用。

此元素是块元素。

此元素需要关闭标签。

Nested COL elements override COLGROUP elements.

Use the SPAN attribute to specify the number of table columns that the COLGROUP defines. This attribute has a default value equal to one.

COL elements can occur outside of a COLGROUP element, and these two elements can be used for similar purposes. However, you must use the COLGROUP element to determine where table internal dividing lines (rules) should go. This is illustrated in the first example below.

You should avoid using the SPAN attribute inside the COLGROUP element if there are COL elements nested within it. This is because the SPAN attribute that belongs to the nested COL elements will override the attribute that belongs to the COLGROUP element. This can cause confusing code and possibly unintended results. This behavior is illustrated in the second example below.

The table object and its associated elements have a separate table object model, which uses different methods than the general object model. For more information on the table object model, see How to Build Tables Dynamically.

This element is available in HTML as of Internet Explorer 3.0, and in script as of Internet Explorer 4.0.

This element is a block element.

This element requires a closing tag.

示例代码

下面的例子使用了 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>
发表回复
你还没有登录,请先登录注册