views:

356

answers:

5

Can anyone explain rowspan and colspan, col and colgroup? And are these W3C valid and semantically correct? Under which circumstances are these useful?

+3  A: 

Yes, they are all recommended by W3C. Here are direct links to the documentation:

RegDwight
+1 for the links.
Andy E
A: 

rowspan and colspan are attributes that allow the designer to 'merge' cells - much like the same command in Excel (for example).

col and colgroup allow the designer to apply css to a vertical column, rather than having to apply css to individual cells in a column. Without these, this task would be much more difficult as html tables are row-based.

All four of these are valid.

For future reference, try http://reference.sitepoint.com/html

adam
A: 

Refer the following URL

http://www.w3schools.com/html/html_tables.asp

muruga
Please don't recommend W3Schools. They usually give examples that avoid best practice as much as possible and are often wrong.
David Dorward
+1  A: 

Have you actually bothered to read the spec yet? Or are you just having trouble understanding it?

<!ELEMENT (TH|TD)  - O (%flow;)*       -- table header cell, table data cell-->

<!-- Scope is simpler than headers attribute for common tables -->
<!ENTITY % Scope "(row|col|rowgroup|colgroup)">

<!-- TH is for headers, TD for data, but for cells acting as both use TD -->
<!ATTLIST (TH|TD)                      -- header or data cell --
  %attrs;                              -- %coreattrs, %i18n, %events --
  abbr        %Text;         #IMPLIED  -- abbreviation for header cell --
  axis        CDATA          #IMPLIED  -- comma-separated list of related headers--
  headers     IDREFS         #IMPLIED  -- list of id's for header cells --
  scope       %Scope;        #IMPLIED  -- scope covered by header cells --
  rowspan     NUMBER         1         -- number of rows spanned by cell --
  colspan     NUMBER         1         -- number of cols spanned by cell --
  %cellhalign;                         -- horizontal alignment in cells --
  %cellvalign;                         -- vertical alignment in cells --
  >

So rowspan is the # of rows a cell spans, same with colspan.

The COLGROUP element creates an explicit column group. The number of columns in the column group may be specified in two, mutually exclusive ways:

  1. The element's span attribute (default value 1) specifies the number of columns in the group.
  2. Each COL element in the COLGROUP represents one or more columns in the group.

Colgroup is used around col elements which can be used to style the columns.

meder
+1 for `Have you actually bothered to read the spec yet?`, if you look at the OP's questions, he asks things like this all the time - you might as well read the spec!
Andy E
What you disliked in my questions?
metal-gear-solid
If i can find on google it doesn't mean should notask on SO
metal-gear-solid
It's more about etiquette. You could have easily first-result googled about half of the 400-500 questions you probably asked TBH. It's fine if you're looking for explanations if you do not understand some descriptions and need someone who understands the language to make it comprehensible ( incase English isn't your first language ) but why ask something so trivial which you can get answered faster by googling than by asking on SO?
meder
By the way, have you actually tried reading the w3 spec yet? Are you having trouble understanding it?
meder
+2  A: 

colspan

<table border="1">
  <tr>
    <th colspan="2">people are...</th>
  </tr>
  <tr>
    <td>monkeys</td>
    <td>donkeys</td>
  </tr>
</table>

rowspan

<table border="1">
  <tr>
    <th rowspan="2">monkeys are...</th>
    <td>... real monkeys</td>
  </tr>
  <tr>
    <td>... 'unreal' monkeys (people...)</td>
  </tr>
</table>

w3c

as you see, this is for connecting table-cells - and because this is sometimes neccessary, it's valid (RegDwights links will give more information...).

col/colgroup

colgroup and col are used to set attributes to every line in the table (so you don't have to write width="80" for the first td in every line(tr)):

<table border="1">
  <colgroup>
    <col width="80">
    <col width="100">
    <col width="320">
  </colgroup>
  <tr>
    <td>first line, first column</td>
    <td>first line, second column</td>
    <td>first line, third column</td>
  </tr>
  <!-- more table-lines... -->
</table>

you can also group the cols, lets say the first and second column should get a with of 80, the third should get 320:

<table border="1">
  <colgroup width="80" span="2"></colgroup>
  <colgroup width="320" span="1"></colgroup>
  <tr>
    <td>first line, first column</td>
    <td>first line, second column</td>
    <td>first line, third column</td>
  </tr>
  <!-- more table-lines... -->
</table>
oezi
oh they naming are opposite as i was thinking. thanks
metal-gear-solid
pls explain col and colgroup
metal-gear-solid
added col/colgroup, hope this helps.
oezi
can we use width="80" ? isn't it deprecated
metal-gear-solid
if i remember right, width is only deprecated for td, th, pre and... something else - but if you don't wand to use it, you can have the same effect by using stylesheets.
oezi