Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

Table Colgroup

HTML Table Colgroup

To style the first two columns of a table, employ the <colgroup> and <col> elements.

IMG_3845

The <colgroup> element serves as a container for column specifications within a table.

Each group is defined using a <col> element.

The span attribute determines the number of columns to be styled.

The style attribute dictates the style to be applied to the columns.

Example

<table>
  <colgroup>
    <col span=”2″ style=”background-color: #D6EEEE”>
  </colgroup>
  <tr>
    <th>MON</th>
    <th>TUE</th>
    <th>WED</th>
    <th>THU</th>
Note: The <colgroup> tag must be nested within a <table> element and positioned before any other table elements such as <thead><tr><td>, etc. However, if a <caption> element exists, it should precede the <colgroup> element.

Legal CSS Properties

Only a restricted set of CSS properties are permitted for use within the colgroup:

  • Width property
  • Visibility property
  • Background properties
  • Border properties

Any other CSS properties applied will not impact your tables.

Multiple Col Elements

To apply distinct styles to additional columns, insert more <col> elements within the <colgroup>.

Example

<table>
  <colgroup>
    <col span=”2″ style=”background-color: #D6EEEE”>
    <col span=”3″ style=”background-color: pink”>
  </colgroup>
  <tr>
    <th>MON</th>
    <th>TUE</th>
    <th>WED</th>
    <th>THU</th>

Empty Colgroups

To style columns in the middle of a table, include an “empty” <col> element (without any styles) for the preceding columns.

Example

<table>
  <colgroup>
    <col span=”3″>
    <col span=”2″ style=”background-color: pink”>
  </colgroup>
  <tr>
    <th>MON</th>
    <th>TUE</th>
    <th>WED</th>
    <th>THU</th>

Hide Columns

You have the option to conceal columns using the visibility: collapse property.

Example

<table>
  <colgroup>
    <col span=”2″>
    <col span=”3″ style=”visibility: collapse”>
  </colgroup>
  <tr>
    <th>MON</th>
    <th>TUE</th>
    <th>WED</th>
    <th>THU</th>

 

Click to Learn