I want to make this template with html tables,
This is my html code
<table>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>
<table>
<tr>
<td>data</td>
<td>data</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>data</td>
<td>data</td>
</tr>
</table>
</td>
<td>data</td>
</tr>
</table>
But it is not giving me the right format like the image above. How can i do it with table?
For the template as per the reference, you need to use this code
table { border: 1px solid #000; border-collapse: collapse; }
table th { padding: 5px 10px; border: 1px solid #000; }
table td { padding: 5px 10px; border-left: 1px solid #000; border-right: 1px solid #000; }
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<th rowspan="2">Sr. No.</th>
<th rowspan="2">Description of Goods</th>
<th rowspan="2">HSN</th>
<th rowspan="2">Qty.</th>
<th rowspan="2">Unit</th>
<th rowspan="2">Rate (per item)</th>
<th rowspan="2">Total</th>
<th rowspan="2">Discount</th>
<th rowspan="2">Taxable Value</th>
<th colspan="2" align="center">CGST</th>
<th colspan="2" align="center">SGST</th>
<th colspan="2" align="center">IGST</th>
</tr>
<tr>
<th>Rate</th>
<th>Amt.</th>
<th>Rate</th>
<th>Amt.</th>
<th>Rate</th>
<th>Amt.</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
Several ways to do this. You could use a table in a td or you could make use of colspan and rowspan like in my example.
Good luck.
table {
border-collapse: collapse;
height: 100px;
font-size: 10px;
text-align: center;
}
td {
padding: 5px;
border: solid 1px black;
}
<table>
<tr>
<td rowspan=2>Sr.No</td>
<td rowspan=2>Description of Goods</td>
<td rowspan=2>HSN</td>
<td rowspan=2>Qty.</td>
<td rowspan=2>Unit</td>
<td rowspan=2>Rate(per item)</td>
<td rowspan=2>Total</td>
<td rowspan=2>Discount</td>
<td rowspan=2>Taxable value</td>
<td colspan=2>CGST</td>
<td colspan=2>SGST</td>
<td colspan=2>IGST</td>
</tr>
<tr>
<td>Rate</td>
<td>Amt.</td>
<td>Rate</td>
<td>Amt.</td>
<td>Rate</td>
<td>Amt.</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
It is called as Table with Irregular Headers
You have to use
<th colspan="2" scope="colgroup">MainHeadername</th>
for main Header and
<th scope="col">SubHeaderName</th>
for Sub Headers
This Reference will be Helpful for further clarifications
https://www.w3.org/WAI/tutorials/tables/irregular/
You can do this using colspan:
table, th, td {
border: 1px solid black;
}
<table>
<tr>
<th>65</th>
<th>80</th>
<th colspan="2">40</th>
<th colspan="2">20</th>
</tr>
<tr>
<th>Men</th>
<th>Women</th>
<th>Men</th>
<th>Women</th>
<th>Men</th>
<th>Women</th>
</tr>
<tr>
<td>82</td>
<td>85</td>
<td>78</td>
<td>82</td>
<td>77</td>
<td>81</td>
</tr>
</table>
Related
How to build this table in html ??
I want to make table using rowspan and colspan ?
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
<table class="table table-bordered">
<thead>
<th>Subject</th>
<th>Result</th>
</thead>
<tbody>
<tr>
<td>Science</td>
<td>Physics</td>
<td>Chemistry</td>
<td>Other Science</td>
<td>Math</td>
<td>English</td>
</tr>
</tbody>
</table>
You can learn about <table> tags at MDN
You can do this:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<table class="table table-bordered">
<thead>
<tr>
<th colspan="2">Subject</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Science</td>
<td>Physics</td>
<td>A</td>
</tr>
<tr>
<td>Chemistry</td>
<td>A</td>
</tr>
<tr>
<td rowspan="2">Other Science</td>
<td>Biology</td>
<td>B</td>
</tr>
<tr>
<td>Geography</td>
<td>A</td>
</tr>
<tr>
<td colspan="2">Math</td>
<td>A+</td>
</tr>
<tr>
<td colspan="2">English</td>
<td>A+</td>
</tr>
</tbody>
</table>
This is set-up with colspan and rowspan
table {
border-collapse: collapse;
}
table,
tr,
th,
td {
border: 1px solid #000;
}
th {
padding: 1ex;
background: #ccc;
}
td {
padding: 1ex;
}
.divide td {
border-top: 3px solid;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<table class="table table-bordered">
<thead>
<th colspan="2">Subject</th>
<th>Result</th>
</thead>
<tbody>
<tr>
<td rowspan="2" colspan="1" width="100px">
SCIENCE
</td>
<td>
Physics
</td>
<td>A</td>
</tr>
<tr>
<td>
<span>Chemistry</span>
</td>
<td colspan="1">A</td>
</tr>
<tr>
<td rowspan="2" colspan="1" width="100px">
SCIENCE
</td>
<td>
Physics
</td>
<td>A</td>
</tr>
<tr>
<td>
<span>Chemistry</span>
</td>
<td colspan="1">A</td>
</tr>
<tr>
<td colspan="2">
SCIENCE
</td>
<td>A</td>
</tr>
<tr>
<td colspan="2">
SCIENCE
</td>
<td>A</td>
</tr>
</tbody>
</table>
<br>
<br>
<table>
<tr>
<th>head</th>
<th>title</th>
<th>title</th>
<th>title</th>
<th></th>
</tr>
<tr>
<td>
<input type="checkbox">
</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td rowspan="2">white</td>
</tr>
<tr>
<td colspan="4">
lorem ipsum
</td>
</tr>
<tr class="divide">
<td>
<input type="checkbox">
</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td rowspan="2">gray</td>
</tr>
<tr>
<td colspan="4">
lorem ipsum
</td>
</tr>
<tr class="divide">
<td>
<input type="checkbox">
</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td>white</td>
</tr>
<tr class="divide">
<td>
<input type="checkbox">
</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td rowspan="2">gray</td>
</tr>
<tr>
<td colspan="4">
lorem ipsum
</td>
</tr>
</table>
I have two tables. One with additional invisible <td> and one without. The problem is that the second table's rowspan is not working, the entire row just collapses. How could I get the result like in the first table without adding that unnecessary <td>?
HTML:
.table-height td {
height: 30px;
}
.invisible {
width: 1px;
}
<p>
<table border="2" class='table-height'>
<tbody>
<tr>
<td rowSpan="2">A1</td>
<td rowSpan="2">A2</td>
<td rowSpan="2">A3</td>
<td rowSpan="2">A4</td>
<td className='invisible'></td>
</tr>
<tr>
<td className='invisible'></td>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
<td className='invisible'></td>
</tr>
<tr>
<td>D1</td>
<td>D2</td>
<td>D3</td>
<td>D4</td>
<td className='invisible'></td>
</tr>
</tbody>
</table>
</p>
<p>
<table border="2" class='table-height'>
<tbody>
<tr>
<td rowSpan="2">A1</td>
<td rowSpan="2">A2</td>
<td rowSpan="2">A3</td>
<td rowSpan="2">A4</td>
</tr>
<tr>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
</tr>
<tr>
<td>D1</td>
<td>D2</td>
<td>D3</td>
<td>D4</td>
</tr>
</tbody>
</table>
</p>
Finally I got it right. I just need to set the height for <tr> too (same as for </td>)
.table-height td, tr {
height: 30px;
}
.invisible {
width: 1px;
}
<p>
<table border="2" class='table-height'>
<tbody>
<tr>
<td rowSpan="2">A1</td>
<td rowSpan="2">A2</td>
<td rowSpan="2">A3</td>
<td rowSpan="2">A4</td>
</tr>
<tr>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
</tr>
<tr>
<td>D1</td>
<td>D2</td>
<td>D3</td>
<td>D4</td>
</tr>
</tbody>
</table>
</p>
I am working on a pay slip design which should be implemented using table structure. I tried a lot but I am still very confused about rowspan and colspan. I also attached the html code below and I need to achieve the entire design in the attached png
<table id="woSpTable" align="center" class="table table-bordered table-responsive table-striped fontsize">
<thead>
<tr>
<th colspan="2"> Employee Details</th>
<th colspan="2">Payment & Leave Details</th>
<th colspan="2">Location Details</th>
<!--<th>ABC</th>-->
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">Item1</td>
<td colspan="2">Item1</td>
<td colspan="2">Item1</td>
<td colspan="4">Item1</td>
</tr>
<tr>
<td>Name1</td>
<td>Price1</td>
</tr>
<tr>
<td>Name2</td>
<td>Price2</td>
</tr>
<tr>
<td>Name3</td>
<td>Price3</td>
</tr>
<tr>
<td>Item2</td>
<td>Item2</td>
<td colspan="2">Item2</td>
<td>Item2</td>
</tr>
</tbody>
</table>
table {
font: 12px 'Arial';
margin: 10px auto;
background: #fff;
text-align: left;
border: 1px solid #000;
border-collapse: collapse;
}
table * { border: 1px solid #000; padding: 5px; white-space: nowrap; }
caption {
background: #fff;
text-transform: uppercase;
text-align: left;
font-weight: bold;
}
tr { background: #fafafb; }
th { color: #fff; background: #0080bf; }
.field { font-weight: bold; }
<table id="woSpTable" align="center" class="table table-bordered table-responsive table-striped fontsize">
<caption>MS. KUSUM KISHORI</caption>
<thead>
<tr>
<th colspan="4">Employee Details</th>
<th colspan="7">Payment & Leave Details</th>
<th colspan="2">Location Details</th>
</tr>
</thead>
<tbody>
<tr>
<td class="field">Emp No.</td>
<td colspan="3">929753</td>
<td class="field">Bank Name</td>
<td colspan="6">AXIS Bank</td>
<td class="field">Location</td>
<td>Item1</td>
</tr>
<tr>
<td class="field">Grade</td>
<td>C1</td>
<td class="field">UAN</td>
<td>10110101013999</td>
<td class="field">Acc No.</td>
<td colspan="6">10110101013999</td>
<td class="field">Base Br.</td>
<td>TSC - Hyderabad</td>
</tr>
<tr>
<td class="field">PAN</td>
<td colspan="3">DROPK7729E</td>
<td class="field">Days paid</td>
<td colspan="6">31</td>
<td class="field">Depute Br.</td>
<td>TSC - Hyderabad</td>
</tr>
<tr>
<td colspan="4"></td>
<td class="field">Leave Balance</td>
<td class="field">EL</td>
<td>36.32</td>
<td class="field">SL</td>
<td>24.32</td>
<td class="field">CL</td>
<td>2.50</td>
<td class="field">WON/SWON</td>
<td>2874529</td>
</tr>
</tbody>
</table>
<table id="woSpTable2" class="table table-bordered table-responsive table-striped fontsize">
<thead>
<tr>
<th>Earnings</th>
<th>Arrears</th>
<th>Current</th>
<th>Deductions</th>
<th>Amount</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2">Total Earnings (Current + Arrears)</td>
<td>34,710.00</td>
<td>Total Deductions</td>
<td>2,817.00</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Op</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Op</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
I'm trying to get an HTML table that looks like the following:
I currently am trying to use the following markup to get this (basically, I multiplied 4 and 6 together to get 24 and used common factors to try to get what I wanted):
<table>
<tbody>
<tr>
<td rowspan="24">1</td>
<td rowspan="4">2</td>
<td rowspan="6">3</td>
</tr>
<tr>
<td rowspan="4">4</td>
<td rowspan="6">5</td>
</tr>
<tr>
<td rowspan="4">6</td>
<td rowspan="6">7</td>
</tr>
<tr>
<td rowspan="4">8</td>
<td rowspan="6">9</td>
</tr>
<tr>
<td rowspan="4">10</td>
</tr>
<tr>
<td rowspan="4">11</td>
</tr>
</tbody>
</table>
However, the above markup doesn't accomplish what I want at all.
Is it possible to get a table like the one shown above using rowspan?
If not with rowspan, are there other ways to get the table above in HTML?
Thanks.
You can achieve the same using following html structure
<table border="1" cellspacing="0" cellpadding="20">
<tbody>
<tr>
<td rowspan="24">1</td>
<td rowspan="4">2</td>
<td rowspan="6">3</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td rowspan="4">4</td>
</tr>
<tr></tr>
<tr>
<td rowspan="6">7</td>
</tr>
<tr></tr>
<tr>
<td rowspan="4">6</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td rowspan="4">8</td>
<td rowspan="6">7</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td rowspan="4">10</td>
</tr>
<tr></tr>
<tr>
<td rowspan="6">9</td>
</tr>
<tr></tr>
<tr>
<td rowspan="4">11</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
</tbody>
</table>
Try this out...
table {
border-collapse: collapse;
border-spacing: 0;
}
table td {
width:60px;
padding: 10px 5px;
border-style: solid;
border-width: 1px;
overflow: hidden;
border-color: black;
}
table th {
width:60px;
font-weight: normal;
padding: 10px 5px;
border-style: solid;
border-width: 1px;
overflow: hidden;
border-color: black;
}
table th {
text-align: left
}
<table class="tg">
<tr>
<th rowspan="12">1</th>
<th rowspan="2">2</th>
<th rowspan="3">3</th>
</tr>
<tr> </tr>
<tr>
<td rowspan="2">4</td>
</tr>
<tr>
<td rowspan="3">5</td>
</tr>
<tr>
<td rowspan="2">6</td>
</tr>
<tr> </tr>
<tr>
<td rowspan="2">7</td>
<td rowspan="3">8</td>
</tr>
<tr> </tr>
<tr>
<td rowspan="2">9</td>
</tr>
<tr>
<td rowspan="3">10</td>
</tr>
<tr>
<td rowspan="2">11</td>
</tr>
</table>
Trying to learn HTML and CSS and I have a simple question.
How can I give each row a different color in a table? For example row 1 is red, row 2 is blue etc.
This is my HTML code:
#table {
font-family: Arial, Helvetica, sans-serif;
width: 600px;
border-collapse;
collapse;
}
#table td,
#table th {
font-size: 12x;
border: 1px solid #4D365B;
padding: 3px 7px 2px 7px;
}
#table th {
font-size: 14px;
text-align: left;
padding-top: px;
padding-bottom: 4px;
background-color: #4D365B;
color: #918CB5;
}
#table td {
color: #000000;
background-color: #979BCA;
}
<table id="table">
<tr>
<th>Company</th>
<th>Contact
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
</table>
If I understand your question correctly and you want to give every row a different color? You have a few options...
Add a class to each row and style those.
Use the direct sibling selector tr + tr
Use :nth-of-type
table tr {background: red;}
table tr:nth-of-type(2) {background: blue;}
table tr:nth-of-type(3) {background: green;}
table tr:nth-of-type(4) {background: yellow;}
table tr:nth-of-type(5) {background: grey;}
<table id="table">
<tr>
<th>Company</th>
<th>Contact
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
</table>
You can also try like this
#table tr{background: red;}
#table tr:nth-child(2n+1){background: blue;}
#table {
font-family: Arial, Helvetica, sans-serif;
width:600px;
border-collapse;collapse;
#table td, #table th {
font-size:12x;
border:1px solid #4D365B;
padding: 3px 7px 2px 7px;
#table th {
font-size:14px;
text-align:left;
padding-top:px;
padding-bottom:4px;
background-color:#4D365B;
color:#918CB5;
#table td {
color:#000000;
background-color:#979BCA;
}
<table id="table">
<tr><th> Company</th><th>Contact<th>Country</th></tr>
<tr><td> 1</td><td>2<td> 3</td></tr>
<tr><td> 1</td><td>2<td> 3</td></tr>
<tr><td> 1</td><td>2<td> 3</td></tr>
This can be done easily using pseudo selectors nth-child.
#table tr:nth-child(odd){background:red}
#table tr:nth-child(even){background:blue}
<table id="table">
<tr><th> Company</th><th>Contact<th>Country</th></tr>
<tr><td> 1</td><td>2<td> 3</td></tr>
<tr><td> 1</td><td>2<td> 3</td></tr>
<tr><td> 1</td><td>2<td> 3</td></tr>
</table>
tr:nth-child(even) {
background: #ff0101;
}
tr:nth-child(odd) {
background: #0030ff;
}
<table class="ex1">
<tbody>
<tr>
<th>Month
</th>
<th>'94
</th>
<th>'95
</th>
<th>'96
</th>
<th>'97
</th>
<th>'98
</th>
<th>'99
</th>
<th>'00
</th>
<th>'01
</th>
<th>'02
</th>
</tr>
<tr>
<td>Jan
</td>
<td>14
</td>
<td>13
</td>
<td>14
</td>
<td>13
</td>
<td>14
</td>
<td>11
</td>
<td>11
</td>
<td>11
</td>
<td>11
</td>
</tr>
<tr>
<td>Feb
</td>
<td>13
</td>
<td>15
</td>
<td>12
</td>
<td>15
</td>
<td>15
</td>
<td>12
</td>
<td>14
</td>
<td>13
</td>
<td>13
</td>
</tr>
<tr>
<td>Mar
</td>
<td>16
</td>
<td>15
</td>
<td>14
</td>
<td>17
</td>
<td>16
</td>
<td>15
</td>
<td>14
</td>
<td>15
</td>
<td>15
</td>
</tr>
<tr>
<td>Apr
</td>
<td>17
</td>
<td>16
</td>
<td>17
</td>
<td>17
</td>
<td>17
</td>
<td>15
</td>
<td>15
</td>
<td>16
</td>
<td>16
</td>
</tr>
<tr>
<td>May
</td>
<td>21
</td>
<td>20
</td>
<td>20
</td>
<td>21
</td>
<td>22
</td>
<td>20
</td>
<td>21
</td>
<td>20
</td>
<td>19
</td>
</tr>
<tr>
<td>Jun
</td>
<td>24
</td>
<td>23
</td>
<td>25
</td>
<td>24
</td>
<td>25
</td>
<td>23
</td>
<td>25
</td>
<td>23
</td>
<td>24
</td>
</tr>
<tr>
<td>Jul
</td>
<td>29
</td>
<td>28
</td>
<td>26
</td>
<td>26
</td>
<td>27
</td>
<td>26
</td>
<td>25
</td>
<td>26
</td>
<td>25
</td>
</tr>
<tr>
<td>Aug
</td>
<td>29
</td>
<td>28
</td>
<td>27
</td>
<td>28
</td>
<td>28
</td>
<td>27
</td>
<td>26
</td>
<td>28
</td>
<td>26
</td>
</tr>
<tr>
<td>Sep
</td>
<td>24
</td>
<td>23
</td>
<td>23
</td>
<td>26
</td>
<td>24
</td>
<td>24
</td>
<td>24
</td>
<td>22
</td>
<td>21
</td>
</tr>
<tr>
<td>Oct
</td>
<td>20
</td>
<td>22
</td>
<td>20
</td>
<td>22
</td>
<td>20
</td>
<td>19
</td>
<td>20
</td>
<td>22
</td>
<td>
</td>
</tr>
<tr>
<td>Nov
</td>
<td>18
</td>
<td>17
</td>
<td>16
</td>
<td>17
</td>
<td>16
</td>
<td>15
</td>
<td>14
</td>
<td>15
</td>
<td>
</td>
</tr>
<tr>
<td>Dec
</td>
<td>15
</td>
<td>13
</td>
<td>13
</td>
<td>14
</td>
<td>13
</td>
<td>10
</td>
<td>13
</td>
<td>11
</td>
<td>
</td>
</tr>
</tbody>
</table>
you can try selecting each row through CSS. In your case:
table tr:first-child{background:red} or table tr:nth-child(1){background:red}
table tr:nth-child(2){background:blue}
table tr:nth-child(3){background:orange}
table tr:nth-child(4){background:yellow}
table tr:last-child{background:purple} or table tr:nth-child(5)
{background:purple}
The below small piece of code should change the color table row.
table, td, th {
border: 1px solid red;
}
th {
background-color: red;
color: black;
}
Source: http://www.snoopcode.com/css/css-tables