HTML Element: <col>
[this page | pdf | back links]
The HTML <col> element indicates the
column properties assigned to each column within a <colgroup>
element. It can be used to apply styles to entire columns in a table.
The attributes it can take (other
than HTML global
attributes and HTML
event attributes) include:
Attribute
|
Description
|
More
|
span
|
Number of columns to
span
|
Here
|
It also used to support
the align, char, charoff,
valign and width attributes, but these are no
longer supported in HTML 5.
To
create or access such an element in JavaScript
see here. The
corresponding HTML DOM
object supports standard
DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The
default style applicable to this element is shown here.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table, th, td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
Created using HTML:<br>
<table>
<colgroup>
<col span="2" style="background-color: yellow">
<col style="background-color: orange">
</colgroup>
<tr><td>1</td><td>2</td><td>3</td></tr>
</table>
<br><br>Created using JavaScript:<br>
<table id="tbl">
<tr><td>1</td><td>2</td><td>3</td></tr>
</table>
<script>
var x = document.createElement("COLGROUP");
var x1 = document.createElement("COL");
var x2 = document.createElement("COL");
x1.setAttribute("span","2");
x1.setAttribute("style","background-color: yellow");
x2.setAttribute("style","background-color: orange");
x.appendChild(x1); x.appendChild(x2);
document.getElementById("tbl").appendChild(x);
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | HTML Elements