HTML table with custom css design - html

What is the proper way to create the table with HTML and CSS like in the image below?
I am struggling with this task for hours now...
The problem is that I don't know how to organize row in the table to have layout like in the image below, all items should be in one row, but I have managed to have all in the separate row.
HTML:
<table class="testTable">
<thead>
<tr>
<th>
<strong>Order</strong>
</th>
<th>
<strong>Operation</strong>
</th>
<th>
<strong>Times</strong>
</th>
<th>
<strong>Quantities</strong>
</th>
<th>
<strong>Date</strong>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="bottom-border">Kamera</td>
<td class="bottom-border" style="color: green;">
<strong>PRODUCTION</strong>
</td>
<td class="bottom-border">7:85</td>
<td class="bottom-border" style="color: green;">GOOD</td>
<td class="bottom-border">26.06.2018.</td>
</tr>
<tr>
<td>Kaciga</td>
<td style="color: orange;">Undefined</td>
<td>7</td>
<td style="color: orange;">SCRAP</td>
<td>26.06.2018.</td>
</tr>
<tr>
<td>Ventil</td>
<td style="color: yellow;">Planned</td>
<td>11</td>
<td style="color: yellow;">REWORK</td>
<td>26.06.2018.</td>
</tr>
<tr>
<td>13</td>
<td style="color: red;">UnPlanned</td>
<td>15</td>
<td style="color: red;">Destroyed</td>
<td>26.06.2018.</td>
</tr>
</tbody>
</table>
CSS:
.bottom-border { border-bottom: solid 1px black; }
.testTable{
font-family: Arial, Helvetica, sans-serif;
width:100%;
border-collapse:collapse;
}
/* Define the default color for all the table rows */
.testTable tr{
background: #f7f6f6;
}
/* Define the hover highlight color for the table row */
.testTable tr:hover {
background-color: #6d7272;
}
Thank you

To provide a slightly more constructive answer, for you to use as a starter for 10. You can utilise CSS3 :nth selectors.
For example:
Selecting odd and even rows:
tr:nth-child(even)
tr:nth-child(odd)
Selecting the first two rows:
tr:nth-child(-n+2)
Read more about nth-child()

Related

How would I achieve a horizontal and vertical hover effect up to a hovered element in a table: How do I create an intersecting hover?

I have a table which has a vertical and horizontal title ("Initial Gravity" and "Final Gravity" respectively), I have a hover effect on my elements, but what I would really like is for my hover to intersect in a manner similar to that shown in the image.
I've used red rectangles in the image purely for representation purposes, I'm hoping to use the same hover as is seen on the hovered element, so the result I'm looking to achieve is a purple bar across the row and a purple bar down the column intersecting on the element the user is hovering over.
If code is needed to help get help, please let me know what code you need to see. The table is a monster at 56 rows and 28 cols so not sure if I should add the entire code or just a snippet.
.card-body table{
width:100%;
}
.blank-cell, th{
background: #000;
color: #fff;
}
td {
text-align: center;
}
th{
background: #000;
color: #fff;
}
td:hover {
background: #530288;
color:white;
}
<table>
<thead>
<tr>
<th></th>
<th></th>
<th>
<div><strong>Final Gravity</strong></div>
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="row-2">
<td class="blank-cell"></td>
<td class="tooltip"></td>
<td class="tooltip">0.990</td>
<td class="tooltip">0.992</td>
<td class="tooltip">0.994</td>
</tr>
<tr class="row-3">
<td class="blank-cell"><strong>Initial Gravity</strong></td>
<td class="tooltip">1.020</td>
<td class="tooltip">3.9</td>
<td class="tooltip">3.7</td>
<td class="tooltip">3.4</td>
</tr>
<tr class="row-4">
<td class="blank-cell"></td>
<td class="tooltip">1.022</td>
<td class="tooltip">4.2</td>
<td class="tooltip">3.9</td>
<td class="tooltip">3.7</td>
</tr>
<tr class="row-5">
<td class="blank-cell"></td>
<td class="tooltip">1.024</td>
<td class="tooltip">4.5</td>
<td class="tooltip">4.2</td>
<td class="tooltip">3.9</td>
</tr>
</tbody>
</table>

Chrome table fluid height needs fix

I have a Chrome table problem as I try make fluid height all rows equals height in standard height table, Firefox is working fine!
https://jsfiddle.net/vdt745er/
table {
height:300px;
border:1px solid #000;
line-height:1;
border-collapse: collapse;
border-spacing: 0;
}
table td, table th{
border:1px solid #000;
padding: 0;
}
<table width="100%" cellpadding="0">
<thead>
<tr>
<td colspan="3" scope="col"> </td>
</tr>
</thead>
<thead>
<tr>
<th scope="col"> </th>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
Any help appreciated
You've hit a bug in chrome. To work around it, remove the thead and tbody tags.
Edit: chrome bug is https://crbug.com/708345 (cells in thead/tfoot don't receive extra height distribution)

How do I arrange content in thead

I wan to arrange columns in my thead to look like the below image
This my code
<thead>
<tr>
<td style="text-align: center;">SUBJECT</td>
<td style="text-align: center;" colspan="3">CA<br> T1 T2 T3</td>
<td style="text-align: center;">CA TOTAL (40)</td>
<td style="text-align: center;">SIGN</td>
</tr>
</thead>
But it displays like this, how can I split the 'CA' column
You need take 2 rows for thead for display.
Here is the complete code
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<thead>
<tr>
<td style="text-align: center;" rowspan='2'>SUBJECT</td>
<td style="text-align: center;" colspan="3">CA</td>
<td style="text-align: center;" rowspan='2'>CA TOTAL (40)</td>
<td style="text-align: center;" rowspan='2'>SIGN</td>
</tr>
<tr>
<td style="text-align: center;">T1</td>
<td style="text-align: center;">T2</td>
<td style="text-align: center;">T3</td>
</tr>
</thead>
</table>
</body>
</html>
You can't split a cell into more cells, you can only merge existing cells together. That said, if you want to have five columns you need to create five columns, and rather than using a <br> to force content to a new line in one cell, and then fake separate cells, use two rows of cells. This, of course, requires the appropriate use of the colspan and rowspan attributes, such as the following:
table {
border-collapse: collapse;
}
th,
td {
text-align: center;
border: 1px solid #000;
min-width: 4em;
min-height: 2em;
padding: 0.2em 0.5em;
}
th {
vertical-align: top;
}
<table>
<thead>
<tr>
<!-- rowspan="2" forces the following <th> element
to span two rows in its containing element: -->
<th rowspan="2">SUBJECT</th>
<th colspan="3">CA</th>
<!-- as it does here also: -->
<th rowspan="2">CA TOTAL (40)</th>
</tr>
<tr>
<!-- this <tr> contains only three <th> elements,
unlike the previous <tr> which contains five,
because two <th> elements of the previous row
will occupy space in this <tr> also -->
<th>T1</th>
<th>T2</th>
<th>T3</th>
</tr>
</thead>
<tbody>
<tr>
<td>English Language</td>
<td>3</td>
<td>6</td>
<td>10</td>
<td></td>
</tr>
<tr>
<td>Mathematics</td>
<td>3</td>
<td>5</td>
<td>7</td>
<td></td>
</tr>
</tbody>
</table>
JS Fiddle demo.
Incidentally, where possible try to style your content via the use of stylesheets; this makes it far easier to update your style and presentation in future.
<thead>
<tr>
<td style="text-align: center;" rowspan='2'>SUBJECT</td>
<td style="text-align: center;" colspan="3">CA</td>
<td style="text-align: center;" rowspan='2'>CA TOTAL (40)</td>
<td style="text-align: center;" rowspan='2'>SIGN</td>
</tr>
<tr>
<td style="text-align: center;">T1</td>
<td style="text-align: center;">T2</td>
<td style="text-align: center;">T3</td>
</tr>
</thead>
Use rowspan and 2 trs
th { vertical-align: top; border: 1px solid black;}
<table>
<thead>
<tr>
<th rowspan="2" style="text-align: center;">SUBJECT</th>
<th style="text-align: center;" colspan="3">CA</th>
<th rowspan="2" style="text-align: center;">CA TOTAL (40)</th>
</tr>
<tr>
<th>T1</th>
<th>T2</th>
<th>T3</th>
</tr>
</thead>
</table>
You can use this. Working perfectly:
<style>
table, th, td{
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
border: 1px solid #000;
}
</style>
<table>
<thead>
<tr>
<th rowspan="2" >SUBJECT</th>
<th colspan="3">CA</th>
<th rowspan="2">CA TOTAL (40)</th>
<th rowspan="2">SIGN</th>
</tr>
<tr>
<th>T1</th>
<th>T2</th>
<th>T3</th>
</tr>
</thead>
<tbody>
<tr>
<td>English Language</td>
<td>3</td>
<td>6</td>
<td>10</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Mathematics</td>
<td>3</td>
<td>5</td>
<td>7</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Custom css to format tr td but not if bold detected inside td

I dont know if this is possible but...I am trying to format a table with css, to have a specific look. This is for a wordpress site that will be updated by my client. The problem is that she is going to be copying/pasting tables with a specific format, and i want the table to have that format without her doing any extra work.
This is what i have so far.
I want the cells with the Bold text to not have a dotted line bellow them.
Right now i am formating the tr lines to add the dotted lines like this:
html
<table class="dotted" border="0" width="450" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2"><strong>Argento</strong></td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong></td>
</tr>
.....
css
.dotted tr:nth-child(even) {
text-decoration: none;
border-bottom: 1px white dotted;
}
.dotted tr:nth-child(odd) {
text-decoration: none;
border-bottom: 1px white dotted;
}
Is there a way i can do this without having to add a custom class tag for each that has the bold text in it ?
This is how i want it to look like, but this is all done manually...That's what i am trying to avoid.
ps: Sometimes the tables might have more than 1 'data' under the bold letters so its not always odd, even lines, when it comes to the 'title' and the 'plays' bellow them. (this is a site for musical plays)
-Thanks
#Manoj Kumar Yeah the bold items are always under colspan 2
Since you stated the above comment, I have a CSS hack for it.
Change your CSS to have dotted border only on td instead of tr elements.
Target the elements with colspan=2 with attribute selector to have no border.
table {
background: gray;
}
.dotted td:nth-child(even) {
text-decoration: none;
border-bottom: 1px white dotted;
}
.dotted td:nth-child(odd) {
text-decoration: none;
border-bottom: 1px white dotted;
}
.dotted td[colspan="2"] { /* Attribute selector */
border: 0 none;
}
<table class="dotted" border="0" width="450" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
</tbody>
</table>

style a <thead>

I have the following :
<table style="border:solid 1px; border-color:black">
<thead style="border:solid 2px; border-color:black">
<tr>
<th>
<p>Document Date</p>
</th>
<th>
<p>Buy-from Vendor No.</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>18/03/11</p>
</td>
<td>
<p>C01753</p>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td>
<p>18/03/11</p>
</td>
<td>
<p>C00522</p>
</td>
</tr>
</tbody>
</table>
I'd like to add a border around the whole table and one around the whole header. The table border is showing nicely (Internet Explorer), but the header border is not.
PS: I use inline styles because it's meant for a HTML body in a mail message.
EDIT
The following gave me what I wanted in Firefox, not in IE though
<table style="border: 1px solid black; border-collapse: collapse;">
<thead>
<tr style="border: 1px solid black">
...
EDIT
Added coloring
<table style="border: 2px solid black; border-collapse: collapse;">
<thead>
<tr style="border: 1px solid black; background-color: #EEE;">
...
Use rules="groups" and change your structure a bit:
<table style="border: 1px solid black; border-collapse: collapse;" rules="groups">
<thead style="border: 2px solid black;">
<tr>
<th>
<p>Document Date</p>
</th>
<th>
<p>Buy-from Vendor No.</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>18/03/11</p>
</td>
<td>
<p>C01753</p>
</td>
</tr>
<tr>
<td>
<p>18/03/11</p>
</td>
<td>
<p>C00522</p>
</td>
</tr>
</tbody>
</table>
EDIT: Well, that doesn's seem to work in IE. In that case, I'd suggest:
<table style="border: 1px solid black; border-collapse: collapse;">
<thead>
<tr style="background-color: black; color: white;">
<!-- ... -->
You can't style a <thead> element, you need to style the <tr>
for example, like this
<table style="border:solid 1px black" cellpadding="0" cellspacing="0">
<thead>
<tr style="background-color: #EEE;">
<th>
<p>Document Date</p>
</th>
<th>
<p>Buy-from Vendor No.</p>
</th>
</tr>
</thead>
...
border styling does not apply, the normal thing is use the background color.
and btw border supports 3 attributes, including the color as well like
border: solid 1px black;
You can't style thead directly, but, you can style the child elements.
For example
<table>
<thead>
<tr>
<th>
<p>Document Date</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<th>
<p>18/03/11</p>
</th>
</tr>
</tbody>
If you want to style just the th of the thead, then your css is
thead th { mystyles }
JSFiddle
Try putting the style on your <tr> rather than <thead>.
Also, you can shorten the css like this: style="border: 2px solid black"
I don't think that that thead renders and is more for organisation. Style the row instead. UPDATE: tr does not support border either. Update version below.
EDIT
<table style="border:solid 1px; border-color:black;border-collapse:collapse;">
<thead>
<tr>
<th style="border:solid 2px black;border-right:none">
<p>Document Date</p>
</th>
<th style="border:solid 2px black;border-left:none">
<p>Buy-from Vendor No.</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>18/03/11</p>
</td>
<td>
<p>C01753</p>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td>
<p>18/03/11</p>
</td>
<td>
<p>C00522</p>
</td>
</tr>
</tbody>
</table>
The border can be specified on a table or a cell (td or th). Specify a top and bottom border on all cells, a left border on the first cell and a right border on the last cell. To prevent gaps between the borders of cells the border-collapse style of the table needs to be set to border-collapse:collapse.