Call Out Individual Columns with col element

Description

You can use the col element instead of the span attribute of the colgroup element to define a group.

col element has local attributes: span.

The align, width, char, charoff, and valign attributes are obsolete.

You can apply styles to groups of columns and the individual columns in that group. The col element is placed inside the colgroup element, and each instance of col represents one column in the group.

Example

The following code uses the col Element.


<!DOCTYPE HTML>
<html>
<head>
<style>
#colgroup1 {<!--  ww  w  . j  a v a2  s. c o m-->
  background-color: red
}

#col3 {
  background-color: green;
  font-size: small
}
</style>
</head>
<body>
  <table>
    <colgroup id="colgroup1">
      <col id="col1And2" span="2" />
      <col id="col3" />
    </colgroup>
    <colgroup id="colgroup2" span="2" />
    <thead>
      <tr>
        <th>Rank</th>
        <th>Name</th>
        <th>Color</th>
        <th colspan="2">Size & Votes</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th>Favorite:</th>
        <td>1234</td>
        <td>1234</td>
        <td>1234</td>
        <td>500</td>
      </tr>
      <tr>
        <th>2nd Favorite:</th>
        <td>1234</td>
        <td>1234</td>
        <td>1234</td>
        <td>450</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Click to view the demo

Note

You can use the span attribute to create a col element that represents two columns in the colgroup.

The col element represents a single column if you don't use the span attribute.

The code above applied a style to the colgroup and to one of the col elements it contains.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed