| Depr. | Version |
|---|---|
| No | HTML 4 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ | CH2+ |
|---|---|---|---|---|
| Full | Full | Full | Full | Full |
Syntax
Description
Just as you can set
th and td elements to span multiple
columns using the colspan attribute, a similar
result can be achieved with the col element using the
span attribute (not
colspan —after all, it’s obvious that it’s a
col that’s being spanned!). However, using this
attribute doesn’t cause any cells to be merged (as does
colspan). Rather, it tells the browser how many
columns or cells the attributes set in the col should
apply to (including the first col). So, in the HTML
example we have a table with four cells in each row—and, therefore, four
columns. But only two col elements are defined, with
span attributes of "2".
Example
Here, the
span is used to group the first two columns
separately from the second two columns, and each group is given a
different class for styling
purposes:
<table border="1" cellpadding="5">
<col class="st1" span="2"/>
<col class="st2" span="2"/>
<tr>
<th colspan="4" scope="col">Work Contact Points</th>
</tr>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Floor/Block</th>
</tr>
⋮
</table>
Value
This attribute takes as its value a
number that represents the number of consecutive cells to which the
col attributes should apply.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
Support for this
attribute has been marked as full, but be aware that this support depends
on whether the other attributes are supported. For instance, Safari
ignores the align attribute, so asking it to span
that attribute across two columns will have no effect. In short, the
successful rendering of span depends on the support
for the attributes with which it’s associated.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.