How can I display rows within rows in table? - html

I am trying to give the effect of general headings in this table and then subdivide such heading into three categories. The table should continue this subdivisions all the way to the end.
I see that I can probably insert a table within a row insert, but don't want to saturate myself with tables.
Is there a way to get this effect in a simpler way?

You can use the Colspan and rowspan attributes to set how far each cell goes across rows and columns.
For example:
<table>
<tbody>
<tr>
<td rowspan="2">Top Left Header</td>
<td colspan="3">Call Standard</td>
</tr>
<tr>
<td>Flagged</td>
<td>Percent</td>
<td>Days</td>
</tr>
</tbody>
</table>
Note that the table ends up with 4 columns. The first row defines one column which crosses 2 rows, and a column which crosses 3 columns.
The second row just fills in the "missing" columns; ignoring the first one because it was defined previously.

You can use rowspan and colspan to achieve this:
<table>
<tr>
<td rowspan="2">Column 1 Heading</td>
<td colspan="3">Call Standard</td>
<td rowspan="2">Column 3 Heading</td>
</tr>
<tr>
<td>Flagged</td>
<td>Percent</td>
<td>Days</td>
</tr>
<tr>
<td>Column 1 Value</td>
<td>4</td>
<td>1%</td>
<td>6</td>
<td>Column 3 Value</td>
</tr>
</table>

Colspan, Rowspan, or Table-Nesting*.
*table-nesting is detestable, but sometimes it's easier to work with than complicated series' of colspans and rowspans.

How about using the "colspan" as defined by the HTML standard? You would apply it to the cell called "call standard" and define it should span over 3 cells.

You don't have to have another inner table... you can have the short row as a full table row, and have header cells that don't subdivide rowspan to span it (and accordingly use colspan on above and below cells).

Related

Is it wise or acceptable to create a table with a different number of columns (td) for each row (tr)

I was wondering if it is wise or acceptable to create a table with a different number of columns (td) for each row (tr) using html. For example:
<table>
<tr>
<td>title</td>
</tr>
<tr>
<td>text</td>
<td>and more text</td>
</tr>
</table>
Do I have to include the colspan?
You do not have to include a colspan=, however, the size of the largest <td></td> will determine the width of the column as it is displayed. Different browsers (and releases) will render the table slightly differently (How the non-defined area is displayed).
Not only is it NOT wise, it's nonconformant with HTML standards.
Use the colspan attribute.

Rowspan upwards

I'm trying to program a javascript timeline, in which you click on the left column revealing something in the right column. I suppose there are easier ways to do this, but the HTML below looks really really neat.
So the usual way rowspan works is that you have a td that you want to extend down a few rows to complete the table.
<tr>
<td>1942</td>
<td rowspan=2>Something happened</td>
</tr>
<tr>
<td>2017</td>
</tr>
However, what if I want to rowspan upwards, so that the below timeline item fills both rows?
<tr>
<td>1942</td>
</tr>
<tr>
<td>2017</td>
<td rowspan=2>Something else happened</td>
</tr>
I know I can just move them all to the top row and rowspan from there, but I really want to have this nice, easy-to-edit format, with dates and rows right next to each other.
(An idea I had was that if you think of rowspan as analogous to css width and height, there might be something analogous to css left and top (like "table-row"?) you could set, other than actually moving the td's to the tr you want. I don't think that exists, though.)
(also, does anyone know if negative rowspan is defined?)
No, rowspan always works “downwards”. HTML 4 does not explicitly say this, but it is definitely implied, and there is no way to change it. HTML5 makes it explicit, in its boringly detailed (but necessary for implementors) Processing model for tables.
I know this is an old question, but I was looking for this myself and this is the first result on google. After a bit of tweaking, I’ve managed to find a solution:
<table>
<thead>
<tr>
<td>Column 1/<td>
<td>Column 2</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan=2>A1</td>
<!--This cell must be hidden; otherwise you will see a gap at the top of the second column between the header and body-->
<td style=“padding:0px;” />
</tr>
<tr>
<td rowspan=3>A</td>
</tr>
<tr>
<td>A2</td>
</tr>
<tr>
<td>A3</td>
</tr>
</tbody>
</table>
You might have to experiment a bit if you want to have a hierarchy deeper than 2 columns, but I’m confident it’s possible.

Table row span cell span

This is an assignment I need help with. I hate tables as is, but this is what it says:
"The first row in each table consists of one table cell which spans two columns that contain the real estate listing name. The second row in each table consists of two table cells."
My code:
<table>
<tr>
<th>
<h3>TEST</h3>
</th>
</tr>
<th rowspan="2"></th>
<td>Something here !</td>
</tr>
</table>
Just wanted to verify if I did this correctly? Here's the full code:
http://jsfiddle.net/4jzUc/
also, it's supposed to look like this: http://screencloud.net/v/aA5Y
You want to span the column, not the row (colspan vs rowspan). I think this is what you are looking for.
<table>
<tr>
<th colspan="2">
Title
</th>
</tr>
<tr>
<td>First cell</td>
</tr>
<tr>
<td>Second cell</td>
</tr>
</table>
No, your markup is not correct. It does not even comply with the HTML table model, as you can see by using http://validator.nu on your document with <!doctype html> slapped at the start. Still less it does do what the assignment calls for.
The assignment as such is very simple: you just a table with two rows and two columns, just so that the first row has only one cell, which spans two columns:
<table>
<tr><td colspan=2>Real estate name
<tr><td>A table cell <td>Another table cell
</table>
You could use th instead of the first td, since it is kind of a header cell, but beware then that this makes its content bold and centered by default (you can override this is in CSS).
As per the “supposed to look like” link, it seems that you are supposed to put an img element only in the first cell of the second row, and the second cell there contains text and a ul element. And a little bit of CSS too. Note that for this output, you will need to align the second row vertically to the top (using the HTML valign attribute or the CSS vertical-align property).
correct code:
<table>
<tr>
<th>
<h3>TEST</h3>
</th>
<th rowspan="2">RowSpan2!</th>
</tr>
<tr>
<td>Something here !</td>
</tr>
<tr>
<td>Something Else !</td>
</tr>
</table>

Table rows become inline if rowspan is set for all the cells of the row

Here is what I need to do.
I'm creating a grid with widgets that are supposed to be represented in a table. Each widget has a variable width that represents the colspan of the td that contains it, and a height of 1 or 2 that is supposed to represent the rowspan of that cells.
Everything works fine, until I'm having a case where all the cells of a row have a colspan of 2, and the next row can have any type of cells. The next row is getting displayed right next to the previous row instead of the next one.
Here is a jsfiddle that replicates the problem and here is the code:
<table>
<tr>
<td rowspan = "2">ONE</td>
</tr>
<tr>
<td rowspan = "1">1</td>
<td rowspan = "1">2</td>
<td rowspan = "1">3</td>
<td rowspan = "1">4</td>
</tr>
</table>
Is this a bug? Am I doing something wrong?
EDIT: To be clear, what I want to do, is having a row of widgets that have twice the height of a regular row
It's difficult to visualize exactly what you want, but perhaps you should be using block elements rather than a table. A table should only be used for tabular data. The rowspan attribute won't function correctly if there aren't any rows to span.
<table>
<tr>
<td rowspan="2">ONE</td>
<td>TWO</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
See the fiddle
Instead of forcing a thing to two rows, which is normally only done when you have more cells in that set of rows, simply set the cell's height:
http://jsfiddle.net/vjPMw/5/
td {
height: 20px;
background-color: #eee;
}
td.doubleheight {
height: 40px;
}
<table>
<tr>
<td class="doubleheight">ONE</td>
</tr>
<tr>
<td rowspan = "1">1</td>
<td rowspan = "1">2</td>
<td rowspan = "1">3</td>
<td rowspan = "1">4</td>
</tr>
</table>
Really, I'd have expected even that to be unnecessary, as a cell normally expands to contain its contents. Maybe a more complete demo of your situation is in order. Also, I agree with Aarolama Bluenk that maybe a table isn't the right approach here to begin with.
The first row has 1 cell with rowspan=2, so html expects next row to be the one which is "spanned", however you've added row with 4 td's.
I'd recommend adding empty <tr></tr> after first one and play with it OR fix first td to: <td rowspan="2" colspan="4">ONE</td>

HTML: Width for a td independent of the upper tr?

if i have a table like following, I didn't make it to define a special width for a single element. Is this possible?
For illustration, i've tried it like this:
<table border="1">
<tr>
<td>Bla</td>
<td>_____________________________________________________</td>
<td>Bla2</td>
</tr>
<tr>
<td>Blub</td>
<td style="width: 100px;">Bli</td>
<td>Hello</td>
</tr>
</table>
Is this possible?
Not really, no. The only thing that exists is the colspan and rowspan attributes that can make a cell span across two columns like so:
<table border="1">
<tr>
<td>Bla</td>
<td>_____________________________________________________</td>
<td>Bla2</td>
</tr>
<tr>
<td colspan="2">Blub Bli - I will span across the whole large line!</td>
<td>Hello</td>
</tr>
</table>
but the exact thing that you want - being completely flexible in cell widths - can be achieved only by two separate tables.
Since you have not specified width explicitly, your other TDs will also be as large as the largest one:
<td>_____________________________________________________</td>
Same is the case with table tag because you have not set width for it too.