asp.net.ph

Skip Navigation Links

COLS Attribute | cols Property

Language References


Please note that this document describes a technology not included in the W3C HTML 4.0 specification, but is available in both Internet Explorer® and Netscape® Navigator® versions 4 and later.

Sets or retrieves the number of columns in the table.

Syntax


Inline <TABLE COLS = iCount...>
Script table.cols = iCount ]

Possible Values


iCount Integer specifying the number of columns.

The property is read/write with no default value.

Remarks

The COLS attribute indicates how many virtual columns of equal width should fit in the width of the browser window. Each actual column in the table occupies a virtual column. Specifying this attribute can speed up the processing of a table.

Authors typically set the COLS attribute to be equal to the number of columns in the table to indicate that all the columns in the table have the same width.

If the TABLE width attribute is supplied, the COLS attribute indicates how many virtual columns fit in the specified width. If width is not supplied, the COLS attribute indicates how many virtual columns should fit in the current window or frame. Each column in the table occupies one of the virtual columns.

Suppose that the table width is set to "80%" and the COLS attribute is 4. As long as the table has from 1 to 4 columns inclusive, each virtual column takes up 20% of the width of the window.

Note, however, that if the minimum width needed to display the contents of an actual column is greater than the width of a virtual column, then the width of the column is expanded to fit its contents.

If the table has more actual columns than the COLS value, then the columns in excess of the COLS value are displayed in the minimum width required to fit their contents, and the other columns divide the remaining space equally between them.

For example, suppose the table has 4 columns, its width set to "80%", and the COLS value set to 3. What happens here is that the table takes up 80% of the width of the window. The fourth column uses the minimum width necessary to display the contents of the column. The other 3 columns divide the remaining width of the table equally between them.

Example

The following example shows use of both the CSS COLS style attribute and the cols property.

<script language="JavaScript">
function checkCols ( oObject ) {
var iColumns = oObject.cols;
alert ( iColumns );
}
</script>
</head>
<body>
<table id=oTable BORDER COLS=3;
   onclick="checkCols ( this )">
<tr>
  <td>Column 1</td>
  <td>Column 2</td>
  <td>Column 3</td></tr>
</table>

This feature requires Microsoft® Internet Explorer® 4.0 or later.

 Show me 

Applies To

TABLE



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note