I am trying to make an HTML table like this:
Name Price Original Value
RED ALL 50 10
A 980 100
B 75 45
YELLOW ALL 500 100
A 550 150
B 80 40
I came up with this but its wrong and looks ugly :( http://jsbin.com/ayixi
Your example updated and working.
I don't know what you were doing in the example because you're missing data etc... The simplest thing to do is just show you how to go about it. Only one of your columns needs a colspan, and only one of your rows needs rowspans to span the rows... (the name column and the color grouping for the rows)
<style>
th {
text-align:left;
}
.endofrow td {
padding-bottom:1em;
}
</style>
<table width="50%" border=1>
<tr><th>Name<th colspan=2>Price<th>Original Value</tr>
<tr><td rowspan=3 valign=top>Red<td>ALL<td>50<td>10</tr>
<tr><td>A<td>980<td>100</tr>
<tr class="endofrow"><td>B<td>80<td>50</tr>
<tr><td rowspan=3 valign=top>Yellow<td>ALL<td>500<td>100</tr>
<tr><td>A<td>980<td>100</tr>
<tr class="endofrow"><td>B<td>80<td>50</tr>
</table>
(note, I've left out the closing tags as they will be filled in and it's easier to read the tables without them)
If you want a space between rows, don't use a <br> or a <br />, they are both a poor solution to the problem. You want to add a class to the final row of that group and put some padding in there. That's the most semantically correct thing to do, and you avoid mixing in line breaks where they don't belong.
You need to look at the colspan and rowspan values. For example in your Table there is the following entry:
<td CLASS="trheadermain" colspan=2 rowspan=3 align="center" height=17>
<B>NAME</B></td>
The rowspan=3 is making the NAMElabel take up too much space
There are some <br> elements that where they don't belong:
</tr>
<br><br><br>
<tr height=20 bgColor=>
You may want to modernize your HTML: use <br /> in place of <br>, <strong> in place of <b>, colspan="2" in place of colspan=2, etc.
The rowspans on the Name, Price and Original Value cells are breaking your layout. It should work alright without these.
<td CLASS="trheadermain" colspan=2 rowspan=3 align="center" height=17 ><B>NAME</B></td>
<td rowspan=2 CLASS="trheadermain" ><B>Price</B></td>
<td rowspan=2 CLASS="trheadermain" ><B>Original Value</B></td>
->
<td CLASS="trheadermain" colspan=2 align="center" height=17 ><B>NAME</B></td>
<td CLASS="trheadermain" ><B>Price</B></td>
<td CLASS="trheadermain" ><B>Original Value</B></td>
Related
I am trying to create an HTML table where there are four columns and any number of rows. Inside this table, the first two columns are just normal cells. The latter two columns can have multiple rows WITHIN a row in the top-level table. My issue is how I can properly align the column separators, even if the length of the content in each cell is variable.
My attempt tries to make use of:
<td colspan=2>
Example of what I am trying to do: https://jsfiddle.net/hurnzhmq/
The things I am missing in the JSFiddle are:
There is no divider between the two rows separating Content3A/Content4A from Content3B/Content4B - I tried using the "bottom-border:none" for the last child, but that did not seem to work.
The column separators between Content3A/Content3B and Content4A/Content4B are not lined up with the header's column separator, and do not touch the ends of the table (there are gaps).
Any advice on how I might go about fixing this would be greatly appreciated!
I think you should use rowspan instead colspan
you can use code below
<html>
<table border=1 >
<tr>
<td>Header1</td>
<td>Header2</td>
<td>Header3</td>
<td>Header4</td>
</tr>
<!-- Content -->
<tr>
<td rowspan="2">Content1</td>
<td rowspan="2" >Content2</td>
<td > Content3A</td>
<td > Content2</td>
</tr>
<tr>
<td > Content3B</td>
<td > Content2</td>
</tr>
</table>
</html>
I have a webpage at http://bikepaths.com/Armstead/GBA1.html , and I have set up an HTML table to arrange text and pictures using rowspan such that the first column has a small amount of text above a tall picture, while the second column has a tall picture above a small amount of text.
<table>
<tr>
<td>George's first memory of note was ... </td>
<td rowspan="2"><img src="image/IM-GBA1885.jpg" height="440" width="280"></td>
</tr>
<tr>
<td rowspan="2"><img src="image/IM-JBA4-GBA.jpg" height="400" width="280"> </td>
</tr>
<tr>
<td>Also he recalled watching his half brother, James Benson Armstead IV <i>[on left]</i>, go through .... </td>
</tr>
</table><br>
So 3 rows, with rowspan=2 on each of the picture cells.
This displays as desired in both Firefox and Chrome, but the MS browsers I have tried (IE11 and Edge) both display it as a simple 2-row table, leaving massive amounts of space above and below each text cell.
I know MS should be banned from creating browsers until they learn what 'following standards' means, but until that happens, is there a workaround to make this display properly in IE and Edge?
<table style="table-layout:fixed">
<tr><td></td><td></td><td></td></tr>
<tr><td colspan="3">three colunms width</td></tr>
<tr><td colspan="2">two columns width</td><td>one column</td></tr>
<tr><td colspan="1">one column</td><td colspan="1">one column</td><td colspan="1">one column</td></tr>
</table>
note that the sum of the colspan attribute values or the sum of the number of td elements in each row equals the number of td elements established by the first (hidden, because the td cells are empty) row.
go to validator.w3.org/nu and copy and paste your markup into the direct input form and then press the validate button.... the w3 validators can detect where the number of td elements and the sum of colspan attributes does not match.
My idea in general: I have HTML Table with custom rows inside. This is similar example:
2nd cell in 1st row - Shold be about 40% of row and 6th cell of 1st row should be a double
8th cell of 2nd row should be big ~ 40%
Basically this 2 rows repeats in my table. Each 2nd row collapsible and it collapse on click in first cell of 1st row. The problem is when I collapse and back my table changes the size of columns and my screen jumps all the time. I want this rows to be always the same structure, but since I have response design I don't want to set exact width for each cell.
I've tried a dozen of variant with colspan and % of width, but nothing work for me.
this is my latest result:
<tr class="mattersRow">
<td colspan="4">
</td>
<td class="editableCell qbmatter" colspan="14"></td>
<td class="editableCell workDate" colspan="4"></td>
<td class="editableCell hours" colspan="2"></td>
<td class="editableCell person" colspan="6"></td>
<td class="rate" colspan="2"></td>
<td class="editableCell amount" colspan="4"></td>
<td align="center"></td>
</tr>
<tr id="collapse63" class="helpRow in" style="height: auto;">
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="4"></td>
<td colspan="2"></td>
<td colspan="4"></td>
<td colspan="2"></td>
<td colspan="16"></td>
<td colspan="4"></td>
</tr>
Can you help me to build this rows properly...
You're on the right track, but tables are designed to have rows and columns end at the same spots, so that little bit of extra space to the right of the 2nd cell in the first row, is either something that will be a ton of work to replicate, or will just be much easier to have them line up. Otherwise you'll start getting into nested tables and it will be more work than it's worth. You could always use a table building generator like TableGenerator
To get that sort of variation you need to have 2 different tables since it will try and align the td's
I would highly suggest putting those into divs with styling. It's pretty clear that you're not using them for tabular data - since you're using it for layout I suggest looking at this question here. This could be achieved relatively easily with some simple css.
http://jsfiddle.net/9p7Mx/1/
I'm sure this has been asked before but I can't find the correct search terms:
If you have an HTML table such as:
<table>
<tr>
<td colspan="2"> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3"> </td>
<td> </td>
</tr>
</table>
The colspan=3 on the last row will not actually line up correctly because you don't actually have 4 td elements. If you look at my example link, I have two tables, one with two tds with colspan=2 and the last with four actual tds. In the first, the td elements are just mimicking 4 tds with their own colspan=2 and thus I assume the table has no way of knowing exactly how large a single colspan is since there is none. Without knowing the exact with on a single colspan, it appears the table doesn't know what to do.
If I can't change the number of td elements in the table, is it possible to get the same effect? I'd rather not assign a width using CSS, and assigning a width WILL work (tested) but I'd like to see if there is another way.
The markup violates the HTML table model, as http://validator.w3.org tells if you use it in HTML5 mode (“Table column 2 established by element td has no cells beginning in it.”). So you should expect inconsistent and unexpected rendering.
If your table logically has just three columns, make it so. Instead of trying to make some columns wider by using colspan, use CSS to set the widths. The colspan=2 attribute means just that the cell spans two columns. And you cannot validly span a column that does not exist.
Using classes and setting the width for the X% you want.
You must consider some divs instead of a table.
I have to make a very complicated table similar to the one in the picture below.
http://irinaciocan.ro/tehnici_web_2012/imagini/tabel_ciudatel29.png
I tried this markup but it doesn't work well.
http://jsfiddle.net/miskolc/W9nJU/3/
<body>
<table border="10" cellpadding="0" cellspacing="0">
<tr>
<td colspan="1" rowspan="1">1</td>
<td colspan="2" rowspan="1">2</td>
<td colspan="2" rowspan="1">3</td>
</tr>
<tr>
<td colspan="2" rowspan="4">4</td>
<td colspan="3" rowspan="2">5</td>
</tr>
<tr>
<td colspan="2" rowspan="2">6</td>
<td colspan="1" rowspan="4">7</td>
</tr>
<tr>
<td rowspan="4" colspan="1">8</td>
<td rowspan="1" colspan="1">9</td>
<td rowspan="1" colspan="1">10</td>
<td rowspan="2" colspan="1">11</td>
</tr>
<tr>
<td rowspan="1" colspan="2">12</td>
</tr>
<tr>
<td rowspan="3" colspan="1">13</td>
<td rowspan="1" colspan="3">14</td>
</tr>
<tr>
<td rowspan="1" colspan="2">15</td>
<td rowspan="1" colspan="1">16</td>
</tr>
<tr>
<td rowspan="1" colspan="2">17</td>
</tr>
</table>
</body>
AND the CSS
td {
width:50px;
height:50px;
padding:0px;
}
I don't understand why cell 6 remains on the same row as cell 5 even though they are inside different tr tags.
I also don't understand why cells 1,2,3 don't have the correct spaning sizes.
Can someone please tell me how to tackle this problem?
Your table should be a 5 columns per 8 rows table (before merging many cells).
All your rows should have a total of 5 columns (or colspan="2" followed by colspan="3" by example). This is the case of the first 2 ones but then it's wrong from the third to the last one.
No fiddle as I won't do it for you ;) Please provide a fiddle where the table is 5C x 8R if there remain(s) a problem
EDIT: OK solved it here: http://jsfiddle.net/W9nJU/5/
The main problem was with the 2nd and 3rd rows: while they've a double height when displayed and make the impression that they occupy 4 rows, they should - no they MUST - be made with only 1 row each.
So the 3 cells "1, 4 and 8" on the left span vertically over resp. 1, 2 and 5 cells (but the cell 4 is twice the height of a cell that would also be spannng over 2 rows).
Modifcations: cell "4" spans over 2 rows (not 4); "5" and "6" no vertical span and resp. span over 2 and 3 columns; cell "7" spans over 3 rows (not 4)
the cell "8" spans over 5 rows and not 4
I think there was, within cells labelled "9"-"17" another value off by 1 but I can't find it anymore. Maybe not.
You're not drawing on a sheet of paper with a fixed-size grid or on a checkerboard. An HTML table is a bit like topology where size doesn't matter and a ring, a mug, a donut and Saturn ring have the same characteristics: "it's just a torus" (if the ring of Saturn wasn't made of a million rings made of blocks... my analogy isn't so good)
At the time the HTML table algorithm build the cells, rows and columns from HTML code (and it can even do so with a few cells lacking!), it has no idea of the size they will have on a graphical browser or on a printer. And a screen reader couldn't care less about that. What is important is the minimal number of cells needed. CSS then use the result to style and display it.