How can I split a row in a html table into multiple (sub) rows? (I don't mean to use rowspan to span multiple rows because I am using a rails gem called sync that is constrained to updating a single table row at a time).
For example, how can I create a single row in a table, that:
in column one, has a single row
in column two, is split into 2 sub rows
in column three, is split into 4 sub rows (row one from the previous column is split into 2 sub rows, and row 2 from the previous column is split into 2 sub rows).
This is just an example. I need to be able to dynamically decide the way the rows will be split at run time.
Edit: see below for structure as described in bullet points above (although note i'm trying to achieve this structure within a single table row, i.e. without using rowspan)
<table>
<tr>
<td rowspan=4>1</td>
<td rowspan=2>2</td>
<td >3</td>
</tr>
<tr>
<td >4</td>
</tr>
<tr>
<td rowspan=2>2</td>
<td >5</td>
</tr>
<tr>
<td >6</td>
</tr>
http://jsfiddle.net/40ukzvz1/
You could try nesting tables so that each table structure is not affected by the cell it sits in.
See code example:
<table width="100%" border bgcolor="red">
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>
<table width="100%" border bgcolor="green">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</td>
<td>
<table width="100%" border bgcolor="blue">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
</table>
</td>
<td>
<table width="100%" border bgcolor="yellow">
<tr>
<td>1</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>
Related
What I want is something like this:
<table>
<tr>
<td>a1</td>
<td>a2</td>
<td>a3</td>
<td>a4</td>
</tr>
</table>
which creates a table like this:
but what I want is something like this:
I know I can easily make it with adding a new row and using rowspan to fix it, but if there is another way to do it without adding another row, it will be so great
You can implement that using rowspan.
<table border="1">
<tr>
<td rowspan="2">a1</td>
<td>a2</td>
<td rowspan="2">a4</td>
</tr>
<tr>
<td>a3</td>
</tr>
</table>
the answer I got after so many searches was this 2 without adding another Row:
adding both a2 a3 to another cell.
using grid system instead of table.
and there are other ways and the easiest ways is by adding another row, the code looks like this:
<table>
<tr>
<td rowspan="2">a1</td>
<td>a2</td>
<td rowspan="2">a4</td>
</tr>
<tr>
<td>a3</td>
</tr>
</table>
<table border="1">
<tr>
<td rowspan="4">A</td>
<td colspan="5">B</td>
</tr>
<tr>
<td colspan="3">E</td>
<td rowspan="2">F</td>
<td rowspan="4">C</td>
</tr>
<tr>
<td rowspan="2">G</td>
<td>
<table border="1">
<tr>
<td>1</td><td>2</td>
</tr>
<tr>
<td>3</td><td>4</td>
</tr>
</table>
</td>
<td>
<table border="1">
<tr>
<td>1</td><td>2</td>
</tr>
<tr>
<td>3</td><td>4</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">H</td>
</tr>
<tr>
<td colspan="5">D</td>
</tr>
</table>
W3C Validator complains, that: "Table column 6 established by element td has no cells beginning in it." even though cell 'C' should begin on 6th column. It displays correctly, so could it be a bug in the validator?
This appears to be a bug in the validator. It somehow fails to analyze the table properly.
Proving this might require a detailed analysis based on the HTML5 table model, but if you just add <col><col><col><col><col><col> right after the <table ...> tag, the markup passes validation – perhaps because it tells the browser that there are six columns and this helps the validator to recognize the status of the C cell properly. I accidentally noticed this when I added the col elements in order to set background colors on columns to visualize the situation better.
Consider posting a bug report and reporting back here if there will be progress there.
So I have a table like so,
<table>
<tbody>
<tr>
<td colspan="6">My 6 headers</td>
</tr>
<tr>
<td colspan="6">My 6 inputs</td>
</tr>
<tr>
<td colspan="3">Indent 3 columns</td>
<td colspan="3">
<table>
<tbody>
<tr>
<td>repeating column 1</td>
<td>repeating column 2</td>
<td>repeating column 3</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
My issue is that, <td>repeating column 1</td> lines up with <td>My 4th input</td> column, but <td>repeating column 2</td> starts immediately after <td>repeating column 1</td> isntead of lining up with <td>My 5th input</td>. How can I align them?
jsFiddle: http://jsfiddle.net/pL89ykLp/
It isn't possible with nested tables unless you set the width to something fixed, and make pixel perfect corrections. This approach is highly unmaintainable.
Instead, don't use tables for layout, and use some proper semantic markup. What kind of semantic markup? That's hard to know without knowing the context of your application.
There's no need for the a nested table in the last tag. Change the second row to this:
<tr>
<td colspan="3">Indent 3 columns</td>
<td>column 1</td>
<td>repeating column 2 </td>
<td>repeating column 3</td>
</tr>
Fiddle:
http://jsfiddle.net/9ywaqf1L/
I'm trying to figure out how it is possible to construct a table with two columns (left and right) so that when left column' content ends the right column takes over it (see example).
I'm sure there's a way to do it without floats but correct me if I'm wrong.
Use colspan like this:
<table>
<tr>
<td>a1</td>
<td>b1</td>
</tr>
<tr>
<td>a2</td>
<td>b2</td>
</tr>
<tr>
<td colspan="2">ab3</td>
</tr>
<tr>
<td colspan="2">ab4</td>
</tr>
</table>
I have a HTML table issue that I'd like to understand better.
Let's assume that I have a 3 row HTML
<table>
<tr>
<td style="text-align:right;">A1</td>
<td>A2</td>
</tr>
<tr>
<td style="text-align:right;">B1</td>
<td>B2</td>
</tr>
<tr>
<td colspan="2">A very loooooooong string here</td>
</tr>
</table>
With a very long text, the contents in the first 2 rows appear like they are nearly centered. However, if I move the whole "A very long string" <td> into a separate <table> inside the row, I see that the other content doesn't center. Why is the display different when the <td> content is inside another table?
If your question ends up with 2 tables, with the original like this:
<table>
<tr>
<td style="text-align:right;">A1</td>
<td>A2</td>
</tr>
<tr>
<td style="text-align:right;">B1</td>
<td>B2</td>
</tr>
</table>
And the looooong text into its own:
<table>
<tr>
<td colspan="2">A very loooooooong string here</td>
</tr>
</table>
Then the reason why the first two lines of the first table no longer look like they're centred is because they're not - ONLY if you're comparing relative to the second table.
If you debug with border="1" in your TABLE attributes, you will see that the table that they are contained in collapses to the widest possible table data cell. Because of this, they don't look like they're centred, even though they still are.
Add some arbitrary width to the first table and you will see that they are still centred.
Can you please provide your second example? When I created the following, it still looked the same. There's a chance you didn't properly embed the table within a table cell with a colspan of 2.
<table border="1">
<tr>
<td style="text-align:right;">A1</td>
<td>A2</td>
</tr>
<tr>
<td style="text-align:right;">B1</td>
<td>B2</td>
</tr>
<tr>
<td colspan="2">
<table border="1"><tr>
<td>A very loooooooong string here</td>
</tr></table>
</td>
</tr>
</table>
When explaining an issue with HTML, it is best to indicate which browsers were used to test...
Anyway, I did a quick test with FF3 and IE6, and I don't see the behavior you describe: with nested table, the long string has slightly more padding but the other content is still visually centered.
You should show your other code. Mine is:
<table>
<tr>
<td style="text-align:right;">A1</td>
<td>A2</td>
</tr>
<tr>
<td style="text-align:right;">B1</td>
<td>B2</td>
</tr>
<tr>
<td colspan="2"><table><tr><td>A very loooooooong string here</td></tr></table></td>
</tr>
</table>
I think I know what you mean, is the second part of your question based on:
<table>
<tr>
<td style="text-align:right;">A1</td>
<td>A2</td>
</tr>
<tr>
<td style="text-align:right;">B1</td>
<td>B2</td>
</tr>
<tr>
<table><td colspan="2">A very loooooooong string here</td></table>
</tr>
</table>
then I guess the reason the table contents are rendered left-aligned is that the inner table tags are hiding the colspan from the outer table.
The answer is to stop using html to style your table and to use CSS instead!