I've created a table with the following custom format:
.table th, td {
border: 1px solid black;
}
<table class="table">
<col />
<colgroup span="2"></colgroup>
<colgroup span="2"></colgroup>
<thead>
<tr>
<td rowspan="2" scope="colgroup">Discipline</td>
<th colspan="2" scope="colgroup">Weight Type 1</th>
<th colspan="1"></th>
<th colspan="2" scope="colgroup">Weight Type 2</th>
</tr>
<tr>
<th scope="col">Weight 1</th>
<th scope="col">Weight 2</th>
<th scope="col">Weight Percentage (%)</th>
<th scope="col">Weight 1</th>
<th scope="col">Weight 2</th>
</tr>
</thead>
<tbody>
<tr style="background-color: white;">
<th scope="row">Discipline 1</th>
<td>10</td>
<td>20</td>
<td>100</td>
<td>2</td>
<td>1</td>
</tr>
<tr style="background-color: white;">
<th scope="row">Discipline 2</th>
<td>20</td>
<td>40</td>
<td>100</td>
<td>4</td>
<td>2</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<b>Summation</b>
</td>
<td>30</td>
<td>60</td>
<td></td>
<td>6</td>
<td>3</td>
</tr>
</tfoot>
</table>
My plan is to create the footer section under Weight Percentage column as the following sample and in the same time, merge and centre the Weight Percentage column:
Is it something possible to create? I tried with rowspan and colspan, but seems like require bit more assistance here.
Yes it is possible with rowspan and colspan, but you need to define extra rows and cols which can then be merged as needed.
.table th,
td {
border: 1px solid black;
}
<table class="table">
<thead>
<tr>
<td>Discipline</td>
<th colspan="2">Weight Type 1</th>
<th colspan="2" rowspan="2" style="border-top:none;">Weight Percentage (%)</th>
<th colspan="2">Weight Type 2</th>
</tr>
<tr>
<th></th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 1</th>
<th>Weight 2</th>
</tr>
</thead>
<tbody>
<tr style="background-color: white;">
<th>Discipline 1</th>
<td>10</td>
<td>20</td>
<td colspan="2">100</td>
<td>2</td>
<td>1</td>
</tr>
<tr style="background-color: white;">
<th>Discipline 2</th>
<td>20</td>
<td>40</td>
<td colspan="2">100</td>
<td>4</td>
<td>2</td>
</tr>
</tbody>
<tfoot>
<tr>
<td rowspan="2">
<b>Summation</b>
</td>
<td rowspan="2">30</td>
<td rowspan="2">60</td>
<td style="width: 80px;">Weight 1</td>
<td style="width: 80px;">X</td>
<td rowspan="2">6</td>
<td rowspan="2">3</td>
</tr>
<tr>
<td>Weight 2</td>
<td>Y</td>
</tr>
</tfoot>
</table>
Related
I've a table that has three rows under weight allowance column at the footer. As you can see it has the three rows as follows:
Weight 1 20
Weight 2 40
Weight 4 60
What I am trying to make that area blank and something as this one: Sample Output
I tried to play around and used colspan or rowspan to make the tweak but seems am unable to do it. Is there any proper workaround for this?
.table th, td {
border: 1px solid black;
}
<table class="table">
<thead>
<tr>
<td>Discipline</td>
<th colspan="3">Weight Type 1</th>
<th colspan="2" rowspan="2">Weight Percentage (%)</th>
<th colspan="3">Weight Type 2</th>
</tr>
<tr>
<th></th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
</tr>
</thead>
<tbody>
<tr style="background-color: white;">
<th>Discipline 1</th>
<td>10</td>
<td>20</td>
<td>30</td>
<td colspan="2">100</td>
<td>2</td>
<td>1</td>
<td>3</td>
</tr>
<tr style="background-color: white;">
<th>Discipline 2</th>
<td>20</td>
<td>40</td>
<td>60</td>
<td colspan="2">100</td>
<td>4</td>
<td>2</td>
<td>6</td>
</tr>
</tbody>
<tfoot>
<tr>
<td rowspan="3">
<b>Summation</b>
</td>
<td rowspan="3">30</td>
<td rowspan="3">60</td>
<td rowspan="3">90</td>
<td style="width: 100px;">Weight 1</td>
<td style="width: 100px;">20</td>
<td rowspan="3">6</td>
<td rowspan="3">3</td>
<td rowspan="3">9</td>
</tr>
<tr>
<td>Weight 2</td>
<td>40</td>
</tr>
<tr>
<td>Weight 4</td>
<td>60</td>
</tr>
</tfoot>
</table>
You'll need rowspan="3" and colspan="2"` on that new empty cell:
.table th, td {
border: 1px solid black;
}
<table class="table">
<thead>
<tr>
<td>Discipline</td>
<th colspan="3">Weight Type 1</th>
<th colspan="2" rowspan="2">Weight Percentage (%)</th>
<th colspan="3">Weight Type 2</th>
</tr>
<tr>
<th></th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
</tr>
</thead>
<tbody>
<tr style="background-color: white;">
<th>Discipline 1</th>
<td>10</td>
<td>20</td>
<td>30</td>
<td colspan="2">100</td>
<td>2</td>
<td>1</td>
<td>3</td>
</tr>
<tr style="background-color: white;">
<th>Discipline 2</th>
<td>20</td>
<td>40</td>
<td>60</td>
<td colspan="2">100</td>
<td>4</td>
<td>2</td>
<td>6</td>
</tr>
</tbody>
<tfoot>
<tr>
<td rowspan="3">
<b>Summation</b>
</td>
<td rowspan="3">30</td>
<td rowspan="3">60</td>
<td rowspan="3">90</td>
<td rowspan="3" colspan="2"></td>
<td rowspan="3">6</td>
<td rowspan="3">3</td>
<td rowspan="3">9</td>
</tr>
<tr>
</tr>
<tr>
</tr>
</tfoot>
</table>
However, now every cell in the bottom row has rowspan="3", so you might want to remove all the rowspans from the bottom row.
I am trying to create a table with the following custom format that has three rows under a column at the end:
.table th, td {
border: 1px solid black;
}
<table class="table">
<thead>
<tr>
<td rowspan="2">Discipline</td>
<th colspan="3">Weight Type 1</th>
<th colspan="1" rowspan="2">Weight Percentage (%)</th>
<th colspan="3">Weight Type 2</th>
</tr>
<tr>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
</tr>
</thead>
<tbody>
<tr style="background-color: white;">
<th>Discipline 1</th>
<td>10</td>
<td>20</td>
<td>30</td>
<td colspan="1">100</td>
<td>2</td>
<td>1</td>
<td>3</td>
</tr>
<tr style="background-color: white;">
<th>Discipline 2</th>
<td>20</td>
<td>40</td>
<td>60</td>
<td colspan="1">100</td>
<td>4</td>
<td>2</td>
<td>6</td>
</tr>
</tbody>
<tfoot>
<tr>
<td rowspan="2">
<b>Summation</b>
</td>
<td rowspan="2">30</td>
<td rowspan="2">60</td>
<td rowspan="2">90</td>
<td style="width: 20px;">Weight 1</td>
<td style="width: 20px;">X</td>
<td rowspan="2">6</td>
<td rowspan="2">3</td>
<td rowspan="2">9</td>
</tr>
<tr>
<td>Weight 2</td>
<td>Y</td>
</tr>
</tfoot>
</table>
What I want, under Weight Percentage column there will be three rows at a time. That means, it'll have something as follows:
Weight 1 - 20
Weight 2 - 40
Weight 4 - 60
For now, under Weight Type 2 area, one of the column Weight 4 is bound out of the table. That has to be adjusted to Weight 4 column. Tried myself, but unable to do it. Anything that I missed?
You have used colspan="1" instead of colspan="2" for the cells of Weight Percentage (%), which causes the 9 to be displayed outside the table since the last rows (since they are merged) now have one more column than the rest. Adjust the three colspan="1" and that problem should be fixed.
As for the third row, you need to actually add a third row (<tr>...</tr>) and then adjust the rowspan for the rows you want to merge in your tfoot.
.table th,
td {
border: 1px solid black;
}
<table class="table">
<thead>
<tr>
<td>Discipline</td>
<th colspan="3">Weight Type 1</th>
<th colspan="2" rowspan="2">Weight Percentage (%)</th>
<th colspan="3">Weight Type 2</th>
</tr>
<tr>
<th></th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
<th>Weight 1</th>
<th>Weight 2</th>
<th>Weight 4</th>
</tr>
</thead>
<tbody>
<tr style="background-color: white;">
<th>Discipline 1</th>
<td>10</td>
<td>20</td>
<td>30</td>
<td colspan="2">100</td>
<td>2</td>
<td>1</td>
<td>3</td>
</tr>
<tr style="background-color: white;">
<th>Discipline 2</th>
<td>20</td>
<td>40</td>
<td>60</td>
<td colspan="2">100</td>
<td>4</td>
<td>2</td>
<td>6</td>
</tr>
</tbody>
<tfoot>
<tr>
<td rowspan="3">
<b>Summation</b>
</td>
<td rowspan="3">30</td>
<td rowspan="3">60</td>
<td rowspan="3">90</td>
<td style="width: 100px;">Weight 1</td>
<td style="width: 100px;">20</td>
<td rowspan="3">6</td>
<td rowspan="3">3</td>
<td rowspan="3">9</td>
</tr>
<tr>
<td>Weight 2</td>
<td>40</td>
</tr>
<tr>
<td>Weight 4</td>
<td>60</td>
</tr>
</tfoot>
</table>
table,
th,
td {
border: 1px solid black;
}
<html>
<table style="border:1px solid;">
<thead>
<tr>
<th rowspan="2">Type</th>
<th colspan="2">Client</th>
<th rowspan="2">Currency</th>
<th rowspan="2">Amount</th>
<th rowspan="2">Monthly Total</th>
<th rowspan="2">Yearly Total</th>
</tr>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr>
<td>Customer</td>
<td colspan="4">
<table style="width:100%">
<tr>
<td>Client A</td>
<td>1234</td>
<td>USD</td>
<td>200</td>
</tr>
<tr>
<td>Client B</td>
<td>5678</td>
<td>USD</td>
<td>200</td>
</tr>
</table>
</td>
<td>300</td>
<td>500</td>
</tr>
<tr>
<td>Vendor</td>
<td colspan="4">
<table>
<tr>
<td>Client C</td>
<td>5678</td>
<td>GBP</td>
<td>100</td>
</tr>
</table>
</td>
<td>300</td>
<td>500</td>
</tr>
</tbody>
</table>
</html>
I have to achieve the above structure , but I am unable to align the inner table to match the width of the from the outer table . tried many things but unable to do it. Could some one please help me ?
So I have a two *ngFor nested , the first one is for the outer table tbody and the second one is for a row for the inner table.
Should you be nesting the table? I would use rowspan instead otherwise your table structure is not semantically correct
table,
th,
td {
border: 1px solid black;
}
<html>
<table style="border:1px solid;">
<thead>
<tr>
<th rowspan="2">Type</th>
<th colspan="2">Client</th>
<th rowspan="2">Currency</th>
<th rowspan="2">Amount</th>
<th rowspan="2">Monthly Total</th>
<th rowspan="2">Yearly Total</th>
</tr>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Customer</td>
<td>Client A</td>
<td>1234</td>
<td>USD</td>
<td>200</td>
<td rowspan="2">300</td>
<td rowspan="2">500</td>
</tr>
<tr>
<td>Client B</td>
<td>5678</td>
<td>USD</td>
<td>200</td>
</tr>
<tr>
<td>Vendor</td>
<td>Client C</td>
<td>5678</td>
<td>GBP</td>
<td>100</td>
<td>300</td>
<td>500</td>
</tr>
</tbody>
</table>
</html>
This kind of thing can be very fiddly. I suggest you save yourself the headache with:
<th>Client Name</th><th>Client ID</th>
If you really have to achieve this structure, use colspan and rowspan.
I have a table that has a caption. To group related information together, I used colspan on the <th> rows (Total divisions and Elevation) so that they serve as "captions" for the cells below them. However, I am not sure if this is the appropriate way of doing it semantically. Particularly, how will I make sure that Total divisions and Elevation would only refer to the rows below them?
<table>
<caption>Summary</caption>
<tr>
<th>Name</th>
<td>Santo Cristo</td>
</tr>
<tr>
<th>Area</th>
<td>67.99 km<sup>2</sup></td>
</tr>
<tr>
<th scope="row" colspan="2">Total divisions</th>
</tr>
<tr>
<th scope="row">Cities</th>
<td>4</td>
</tr>
<tr>
<th scope="row">Villages</th>
<td>45</td>
</tr>
<tr>
<th scope="row" colspan="2">Elevation (masl)</th>
</tr>
<tr>
<th scope="row">Highest point</th>
<td>12 meters</td>
</tr>
<tr>
<th scope="row">Lowest point</th>
<td>0 meters</td>
</tr>
</table>
Group your rows into <tbody> elements and scope each summary <th> to its parent <tbody> with scope="rowgroup" in lieu of scope="row", like so:
<table>
<caption>Summary</caption>
<thead>
<tr>
<th>Name</th>
<td>Santo Cristo</td>
</tr>
<tr>
<th>Area</th>
<td>67.99 km<sup>2</sup></td>
</tr>
</thead>
<tbody>
<tr>
<th scope="rowgroup" colspan="2">Total divisions</th>
</tr>
<tr>
<th scope="row">Cities</th>
<td>4</td>
</tr>
<tr>
<th scope="row">Villages</th>
<td>45</td>
</tr>
</tbody>
<tbody>
<tr>
<th scope="rowgroup" colspan="2">Elevation (masl)</th>
</tr>
<tr>
<th scope="row">Highest point</th>
<td>12 meters</td>
</tr>
<tr>
<th scope="row">Lowest point</th>
<td>0 meters</td>
</tr>
</tbody>
</table>
(The first group can be either a <thead> or another <tbody> depending on your preference, but what's important are the two groups you're trying to scope the <th> elements to.)
I'd like to make an HTML table with a "<th> split", like this:
I tried to make the HTML table by splitting the <th> tag using rowspan and colspan, but I need it exactly like in the image.
No need for rowspan as you will use an inner table to compose the 4 rows JS Fiddle
table {
width: 98%;
height: 160px;
margin: 0 auto;
text-align: center;
border-collapse: collapse;
}
td {
border: 2px solid black;
}
#t1 table {
width: 100%;
}
<table id="t1">
<tr>
<td>TD</td>
<td>TD</td>
<td>TD</td>
<td>
<table>
<tr>
<td>TD</td>
<td>TD</td>
</tr>
<tr>
<td>TD</td>
<td>TD</td>
</tr>
<tr>
<td colspan="2">TD</td>
</tr>
<tr>
<td>TD</td>
<td>TD</td>
</tr>
</table>
</td>
<td>TD</td>
<td>TD</td>
</tr>
</table>
Here's what I could come up with: https://jsfiddle.net/ryrL79pr/
<html>
<body>
<table>
<tr>
<th rowspan="4">A</th>
<th rowspan="4">B</th>
<th rowspan="4">C</th>
<th>
<table>
<tr>
<th>1</th>
<th>2</th>
</tr>
</table>
</th>
<th rowspan="4">D</th>
<th rowspan="4">E</th>
<th rowspan="4">F</th>
</tr>
<tr>
<th>
<table>
<tr>
<th>1</th>
<th>2</th>
</tr>
</table>
</th>
</tr>
<tr>
<th>3</th>
</tr>
<tr>
<th>
<table>
<tr>
<th>1</th>
<th>2</th>
</tr>
</table>
</th>
</tr>
</table>
Hope that helps!
<tr>
<th rowspan="3">Client</th>
<th rowspan="3">Apt No</th>
<th rowspan="3">Sq.ft Area</th>
<th rowspan="3">Listed Price</th>
<th>Date 28-FEB-2015</th>
<th>Date 28-FEB-2015</th>
<th>Date 28-FEB-2015</th>
</tr>
<tr>
<th>1st Instalment</th>
<th>2nd Instalment</th>
<th>3rd Instalment</th>
</tr>
<tr>
<th>10% status</th>
<th>10% status</th>
<th>10% status</th>
</tr>
</table>
No need to css https://jsfiddle.net/parthmy007/s7v70dk7/
<table border="1">
<thead>
<tr>
<th rowspan="4">Items</th>
<th rowspan="4">Type</th>
<th rowspan="4">Type</th>
<th colspan="4">Values</th>
<th>Values</th>
<th rowspan="4">Date</th>
<th rowspan="4">Date</th>
</tr>
<tr>
<th colspan="4">Before</th>
<th >Before</th>
</tr>
<tr>
<th colspan="5">Before</th>
</tr>
<tr>
<th colspan="4">Before</th>
<th >Before</th>
</tr>
</thead>
<tbody></tbody>
</table>
https://jsfiddle.net/parthmy007/s7v70dk7/