Merge and Make A Blank Space - html

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.

Related

Table Footer With Three Split 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 Footer With Two Split Row

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>

Nested ( master detail ) table in html

I added child table in tr but I am unable to make a grid like shown in mockup.
Basically, I got the idea from dev extreme grid. https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/MasterDetailView/Angular/Light/
You should be able to use further <tr>, <td>, <th> elements to do what you need, since it seems like you want to keep the same table layout for the pseudo-child-tables:
<table>
<thead>
<tr>
<th>Teader Id</th>
<th>Name</th>
<th>address</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>ABC</td>
<td>32 block</td>
<td></td>
</tr>
<tr>
<th></th>
<th>Student Id</th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td></td>
<td>11</td>
<td>DEF</td>
<td>Male</td>
</tr>
<tr>
<td>2</td>
<td>GHI</td>
<td>32 block</td>
<td></td>
</tr>
<tr>
<th></th>
<th>Student Id</th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td></td>
<td>12</td>
<td>JKL</td>
<td>Male</td>
</tr>
<tr>
<td>3</td>
<td>MNO</td>
<td>32 block</td>
<td></td>
</tr>
<tr>
<th></th>
<th>Student Id</th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td></td>
<td>11</td>
<td>PQR</td>
<td>Male</td>
</tr>
</tbody>
</table>

It is possible to make a vertical table with horizontal headers?

I'm trying to create a vertical table, with headers on specific areas such as a user's address. I want to create something like this:
General Information
Name John Smith
Date of Birth April 1, 1984
Gender Male
Account Information
Correspondence Address
Address 1 1234 MLK Blvd
Address 2 502
City Kansas City
State Missouri
Country USA
Zip Code 55748
Residential Address
Address 1 143 St Michael's Way
Address 2
City Independence
State Missouri
Country USA
Zip Code 55760
I am currently using this code for the table without headers:
<table>
<tr id='Name'>
<th>Name</th>
</tr>
<tr id='PersonEmail'>
<th>Email</th>
</tr>
<tr id='Gender'>
<th>Gender</th>
<td></td>
</tr>
<tr id='Date_of_Birth'>
<th>Date of Birth</th>
<td></td>
</tr>
</table>
How do I add headers at the top of the table?
give colspan as a desired value to occupy the position as headers
<table>
<tr>
<td colspan='2'>General Information</td>
</tr>
<tr >
<td >Name </td>
<td > John Smith </td>
</tr>
<tr>
<td >Date of Birth</td>
<td > April 1, 1984</td>
</tr>
</table>
demo here, code here:
<table border="1">
<tr>
<th colspan="2">Header</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$100</td>
</tr>
<tr>
<th colspan="2">Header2</th>
</tr>
</table>
<table>
<tr><td colspan="2">Title 1</td></tr>
<tr id='Name'>
<th>Name</th>
</tr>
<tr><td colspan="2">Title 2</td></tr>
<tr id='PersonEmail'>
<th>Email</th>
</tr>
...
</table>
<table>
<tr>
<td></td>
<td colspan="2">General Information</td>
</tr>
<tr id='Name'>
<th>Name</th>
<td></td>
</tr>
<tr id='PersonEmail'>
<th>Email</th>
<td></td>
</tr>
<tr id='Gender'>
<th>Gender</th>
<td></td>
<td></td>
</tr>
<tr id='Date_of_Birth'>
<th>Date of Birth</th>
<td></td>
</tr>
It's just a case of rearranging the <td>'s and <th>'s
Table headers (or "captions") are simply an extra tag.
Option 1: (traditional)
<table>
<caption>General Information</caption>
<tr>
<th>Name</th>
<td>John Smith</td>
</tr>
<tr>
<th>Date of Birth</th>
<td>April 1, 1984</td>
</tr>
<tr>
<th>Gender</th>
<td>Male</td>
</tr>
</table>
<table>
<caption>Account Information</caption>
</table>
<table>
<caption>Correspondence Address</caption>
<tr>
<th>Address 1</th>
<td>1234 MLK Blvd</td>
</tr>
<tr>
<th>Address 2</th>
<td>502</td>
</tr>
<tr>
<th>City</th>
<td>Kansas City</td>
</tr>
<tr>
<th>State</th>
<td>Missouri</td>
</tr>
<tr>
<th>Country</th>
<td>USA</td>
</tr>
<tr>
<th>Zip Code</th>
<td>55748</td>
</tr>
</table>
<table>
<caption>Residential Address</caption>
<tr>
<th>Address 1</th>
<td>143 St Michael's Way</td>
</tr>
<tr>
<th>Address 2</th>
<td></td>
</tr>
<tr>
<th>City</th>
<td>Independence</td>
</tr>
<tr>
<th>State</th>
<td>Missouri</td>
</tr>
<tr>
<th>Country</th>
<td>USA</td>
</tr>
<tr>
<th>Zip Code</th>
<td>55760</td>
</tr>
</table>
Option 2: (Using additional tr as a sub-header)
<table>
<tr>
<th colspan="2" class="caption">General information</th>
</tr>
<tr>
<th>Name</th>
<td>John Smith</td>
</tr>
<tr>
<th>Date of Birth</th>
<td>April 1, 1984</td>
</tr>
<tr>
<th>Gender</th>
<td>Male</td>
</tr>
<tr>
<th colspan="2" class="caption">Account Information</th>
</tr>
<tr>
<!-- Account Info -->
</tr>
<tr>
<th colspan="2" class="caption">Correspondence Address</th>
</tr>
<tr>
<th>Address 1</th>
<td>1234 MLK Blvd</td>
</tr>
<tr>
<th>Address 2</th>
<td>502</td>
</tr>
<tr>
<th>City</th>
<td>Kansas City</td>
</tr>
<tr>
<th>State</th>
<td>Missouri</td>
</tr>
<tr>
<th>Country</th>
<td>USA</td>
</tr>
<tr>
<th>Zip Code</th>
<td>55748</td>
</tr>
<tr>
<th colspan="2" class="caption">Residential Address</th>
</tr>
<tr>
<th>Address 1</th>
<td>143 St Michael's Way</td>
</tr>
<tr>
<th>Address 2</th>
<td></td>
</tr>
<tr>
<th>City</th>
<td>Independence</td>
</tr>
<tr>
<th>State</th>
<td>Missouri</td>
</tr>
<tr>
<th>Country</th>
<td>USA</td>
</tr>
<tr>
<th>Zip Code</th>
<td>55760</td>
</tr>
</table>

Vertical and Horizontal Headers in a table?

How would I get a table with both horizontal and vertical headers?
So e.g.
header1 header2 header3
header1 1 1 1
header2 2 2 2
header3 3 3 3
Like #UlrichSchwarz said, you can just use <th> instead of <td> in the first column. Using scope, you can make it more semantically descriptive:
<table>
<tr>
<th></th>
<th scope="col">header1</th>
<th scope="col">header2</th>
<th scope="col">header3</th>
</tr>
<tr>
<th scope="row">header 1</th>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th scope="row">header 2</th>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<th scope="row">header 3</th>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
</table>
While you can still just <th> the entries in the first column, there is no column-equivalent of <thead>/<tbody> that I'm aware of.
easy. Just leave the first td in the first tr - empty
You can make it with quite elementary HTML and CSS classes:
table{border-collapse:collapse}
td{text-align:center;padding:5px;border:1px solid #000}
td.empty{border:0}
td.headt{font-weight:bold;background-color:#b7f926}
<table>
<tr>
<td class="empty"> </td>
<td class="headt">Header 1</td>
<td class="headt">Header 2</td>
<td class="headt">Header 3</td>
</tr>
<tr>
<td class="headt">Header 1</td><td>1</td><td>2</td><td>3</td>
</tr>
<tr>
<td class="headt">Header 2</td><td>1</td><td>2</td><td>3</td>
</tr>
<tr>
<td class="headt">Header 3</td><td>1</td><td>2</td><td>3</td>
</tr>
</table>
This is just a sketch/suggestion, but hopefully useful to compare for future readers :)