Freezing Top Row of a table for website - html

I am using Tableizer to convert my excel worksheet into HTML code then paste into my website. I'm trying to make my table scrollable. I can't figure out where or how to insert the options listed here: Freezing/Fixing the Top Header Row of a table
Can anyone help??
Here is my code from Tableizer.com
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-align:center;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
text-align:center;
}
.tableizer-table th {
background-color: #C61F13;
color: #FFF;
font-weight: bold;
text-align:center;
}
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th width="5%">District</th><th width="5%">Dlr Code</th><th width="20%">Dealer Name</th><th width="5%">Kia CPO Volume Obj</th><th width="5%">Current Standings</th><th width="5%">Enrolled</th><th width="5%">To Go</th></tr>
<tr><td>CE01</td><td>IL001</td><td>ARLINGTON KIA IN PALATINE</td><td>30 </td><td>8</td><td>yes</td><td>22</td></tr>
<tr><td>CE01</td><td>IL003</td><td>LIBERTY KIA</td><td>30 </td><td>2</td><td>yes</td><td>28</td></tr>
<tr><td>CE01</td><td>IL035</td><td>NAPLETON'S KIA OF ELMHURST</td><td>32 </td><td>11</td><td>yes</td><td>21</td></tr>
<tr><td>CE01</td><td>IL036</td><td>ROCK RIVER KIA</td><td>30 </td><td>0</td><td>no</td><td>30</td></tr>
<tr><td>CE01</td><td>IL051</td><td>RAYMOND KIA</td><td>30 </td><td>3</td><td>yes</td><td>27</td></tr>
<tr><td>CE01</td><td>IL054</td><td>GERALD KIA OF NAPERVILLE</td><td>30 </td><td>16</td><td>yes</td><td>14</td></tr>
<tr><td>CE01</td><td>IL057</td><td>GARY LANG KIA</td><td>30 </td><td>11</td><td>yes</td><td>19</td></tr>
<tr><td>CE01</td><td>IL058</td><td>CLASSIC KIA</td><td>30 </td><td>2</td><td>yes</td><td>28</td></tr>
<tr><td>CE01</td><td>IL060</td><td>GROSSINGER KIA</td><td>30 </td><td>0</td><td>yes</td><td>30</td></tr>
<tr><td>CE01</td><td>IL064</td><td>BOB ROHRMAN SCHAUMBURG KIA</td><td>30 </td><td>0</td><td>no</td><td>30</td></tr>
<tr><td>CE01</td><td>IL071</td><td>GERALD KIA OF NORTH AURORA</td><td>30 </td><td>13</td><td>yes</td><td>17</td></tr>
<tr><td>CE01</td><td>IL072</td><td>NAPLETON'S ELGIN KIA</td><td>30 </td><td>20</td><td>yes</td><td>10</td></tr>
<tr><td>CE02</td><td>OH003</td><td>HALLEEN KIA</td><td>90 </td><td>54</td><td>yes</td><td>36</td></tr>
<tr><td>CE02</td><td>OH016</td><td>WAIKEM KIA</td><td>30 </td><td>15</td><td>no</td><td>15</td></tr>
<tr><td>CE02</td><td>OH025</td><td>TAYLOR KIA</td><td>37 </td><td>1</td><td>yes</td><td>36</td></tr>
</table>

There is no real pretty way to do this.
You will need to take the are you want to be the head out of your table and into a new table and style it like bellow.
all in all ending up with something like this.
you'll will need to match up your column widths though.
if your table is to be a full page let me know and I can show you a way to do it for a larger table.
here is a fiddle
table.tableizer-table {
border: 1px solid #CCC;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-align: center;
width: 100%;
height: 300px;
overflow: scroll;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
text-align: center;
}
.tableizer-table th {
background-color: #C61F13;
color: #FFF;
font-weight: bold;
text-align: center;
}
.headtbl {
background-color: red;
}
.container {
position: relative;
width: 100%;
}
.tablearea {
height: 300px;
overflow-y: scroll;
}
<div class="container">
<table class="headtbl">
<tr class="tableizer-firstrow">
<th width="5%">District</th>
<th width="5%">Dlr Code</th>
<th width="20%">Dealer Name</th>
<th width="5%">Kia CPO Volume Obj</th>
<th width="5%">Current Standings</th>
<th width="5%">Enrolled</th>
<th width="5%">To Go</th>
</tr>
</table>
<div class="tablearea">
<table class="tableizer-table">
<tr>
<td>CE01</td>
<td>IL001</td>
<td>ARLINGTON KIA IN PALATINE</td>
<td>30</td>
<td>8</td>
<td>yes</td>
<td>22</td>
</tr>
<tr>
<td>CE01</td>
<td>IL003</td>
<td>LIBERTY KIA</td>
<td>30</td>
<td>2</td>
<td>yes</td>
<td>28</td>
</tr>
<tr>
<td>CE01</td>
<td>IL035</td>
<td>NAPLETON'S KIA OF ELMHURST</td>
<td>32</td>
<td>11</td>
<td>yes</td>
<td>21</td>
</tr>
<tr>
<td>CE01</td>
<td>IL036</td>
<td>ROCK RIVER KIA</td>
<td>30</td>
<td>0</td>
<td>no</td>
<td>30</td>
</tr>
<tr>
<td>CE01</td>
<td>IL051</td>
<td>RAYMOND KIA</td>
<td>30</td>
<td>3</td>
<td>yes</td>
<td>27</td>
</tr>
<tr>
<td>CE01</td>
<td>IL054</td>
<td>GERALD KIA OF NAPERVILLE</td>
<td>30</td>
<td>16</td>
<td>yes</td>
<td>14</td>
</tr>
<tr>
<td>CE01</td>
<td>IL057</td>
<td>GARY LANG KIA</td>
<td>30</td>
<td>11</td>
<td>yes</td>
<td>19</td>
</tr>
<tr>
<td>CE01</td>
<td>IL058</td>
<td>CLASSIC KIA</td>
<td>30</td>
<td>2</td>
<td>yes</td>
<td>28</td>
</tr>
<tr>
<td>CE01</td>
<td>IL060</td>
<td>GROSSINGER KIA</td>
<td>30</td>
<td>0</td>
<td>yes</td>
<td>30</td>
</tr>
<tr>
<td>CE01</td>
<td>IL064</td>
<td>BOB ROHRMAN SCHAUMBURG KIA</td>
<td>30</td>
<td>0</td>
<td>no</td>
<td>30</td>
</tr>
<tr>
<td>CE01</td>
<td>IL071</td>
<td>GERALD KIA OF NORTH AURORA</td>
<td>30</td>
<td>13</td>
<td>yes</td>
<td>17</td>
</tr>
<tr>
<td>CE01</td>
<td>IL072</td>
<td>NAPLETON'S ELGIN KIA</td>
<td>30</td>
<td>20</td>
<td>yes</td>
<td>10</td>
</tr>
<tr>
<td>CE02</td>
<td>OH003</td>
<td>HALLEEN KIA</td>
<td>90</td>
<td>54</td>
<td>yes</td>
<td>36</td>
</tr>
<tr>
<td>CE02</td>
<td>OH016</td>
<td>WAIKEM KIA</td>
<td>30</td>
<td>15</td>
<td>no</td>
<td>15</td>
</tr>
<tr>
<td>CE02</td>
<td>OH025</td>
<td>TAYLOR KIA</td>
<td>37</td>
<td>1</td>
<td>yes</td>
<td>36</td>
</tr>
</table>
</div>
</div>

Related

th and td with background color and text color not changing background color with hover?

I'm making a calendar for a school assignment and I decided to add 'hover' so when the mouse hovers over the table header/data, it will change its background color. It works as intended on the uncolored table header/data, but it doesn't change the background color on the ones with a red background color and white text color.
here's the code.
<html lang="eng">
<head>
<title>Computer 8 Quiz 3 | 4th Quarter</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
text-align: center;
padding: 10px 0px
}
th:hover {background-color: #BBBBBB}
td:hover {background-color: #BBBBBB}
</style>
</head>
<body style="text-align: center;">
<div style="margin: 0px 100px; padding: 20px 5px">
<div>
<header>
<h1>2022 Calendar</h1>
</header>
</div>
<br>
<div>
<table width="700" style="margin-right: auto; margin-left: auto;">
<tr>
<th colspan="7"><span style="font-size: 25px;">May</span></th>
</tr>
<tr>
<th style="background-color: #f5425a; color: white">SUN</th>
<th style="background-color: #f5425a; color: white">MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">1</td>
<td style="background-color: #f5425a; color: white">2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">8</td>
<td style="background-color: #f5425a; color: white">9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">15</td>
<td style="background-color: #f5425a; color: white">16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">22</td>
<td style="background-color: #f5425a; color: white">23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">29</td>
<td style="background-color: #f5425a; color: white">30</td>
<td>31</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
</div>
<br><br><br><br><br><br>
<div style="text-align: left;">
<footer>
<p>Author: Brent Lee de Guzman</p>
Contact me here!
</footer>
</div>
</body>
</html>
How do I make the colored-background ones change their background color on hover too? I'm a really confused on this one, and I'm trying to find the reason why this happens. Please help me on this problem, thanks in advance!
From MDN
Inline styles added to an element (e.g., style="font-weight: bold;") always overwrite any styles in external stylesheets, and thus can be thought of as having the highest specificity.
There are various ways you can get hover to change the color of even those elements.
A quick, and often regarded as rather dirty, way of overriding this is to give the hover settings in the stylesheet !important additions as in this snippet:
<html lang="eng">
<head>
<title>Computer 8 Quiz 3 | 4th Quarter</title>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
text-align: center;
padding: 10px 0px
}
th:hover {
background-color: #BBBBBB !important
}
td:hover {
background-color: #BBBBBB !important
}
</style>
</head>
<body style="text-align: center;">
<div style="margin: 0px 100px; padding: 20px 5px">
<div>
<header>
<h1>2022 Calendar</h1>
</header>
</div>
<br>
<div>
<table width="700" style="margin-right: auto; margin-left: auto;">
<tr>
<th colspan="7"><span style="font-size: 25px;">May</span></th>
</tr>
<tr>
<th style="background-color: #f5425a; color: white">SUN</th>
<th style="background-color: #f5425a; color: white">MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">1</td>
<td style="background-color: #f5425a; color: white">2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">8</td>
<td style="background-color: #f5425a; color: white">9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">15</td>
<td style="background-color: #f5425a; color: white">16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">22</td>
<td style="background-color: #f5425a; color: white">23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<td style="background-color: #f5425a; color: white">29</td>
<td style="background-color: #f5425a; color: white">30</td>
<td>31</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
</div>
<br><br><br><br><br><br>
<div style="text-align: left;">
<footer>
<p>Author: Brent Lee de Guzman</p>
Contact me here!
</footer>
</div>
</body>
</html>
However, a more maintainable alternative may be to remove inline styling altogether and use classes instead of inline style.
Depending on your exact use case you may be able to go further and use child selectors on each row (except the first) to select the first and second elements without using a separate class.

CSS class styles affecting HTML elements outside of class definition

Style properties defined under one class affects the properties of another element with a different class definition.
Specifically the styles for the th and td from the Movement table are overwriting the ones defined in the Characteristics table. Inspecting the styles within Chrome it clearly shows that the Movement styles are trumping the Characteristic settings.
A working example of the code is below. It can run at this link from w3chools.com.
I've tried numerous variations and have been unable to correct it. Checked here and other sites for solutions but to no avail.
I'd really like to know what I'm doing wrong. Thanks.
.grid-container-0 {
display: grid;
grid-gap: 1px;
grid-template-columns: auto auto 5px auto;
width: 200mm;
border: solid black thin;
padding: 0px;
background-color: white;
}
.grid-container-2 {
display: grid;
grid-gap: 1px;
border: none;
padding: 2px;
background-color: white;
}
.grid-container-5 {
display: grid;
grid-gap: 1px;
border: none;
padding: 1px;
background-color: white;
}
.title {
padding: 2px;
text-align: left;
font-size: 12pt;
font-weight: bold;
color: white;
background-color: black;
}
div.characteristics {
grid-row: 2;
grid-column: 1 / span 2;
}
.characteristics th,
td {
padding: 2px;
text-align: center;
font-size: 10pt;
}
.characteristics th:last-of-type,
td:last-of-type {
text-align: left;
}
.characteristics tr:last-of-type {
font-weight: bold;
}
div.movement {
grid-row: 4;
grid-column: 2;
}
.movement th,
td {
margin: 0px;
padding: 0px 2px;
text-align: left;
font-size: 8pt;
}
<body>
<div class="grid-container-0">
<div class="grid-item characteristics">
<div class="grid-container-2">
<div class="grid-item characteristics-1 title">CHARACTERISTICS</div>
<div class="grid-item characteristics-2">
<table>
<tr>
<th>Val</th>
<th>Char</th>
<th>Points</th>
<th>Roll</th>
<th>Notes</th>
</tr>
<tr>
<td>10</td>
<td>STR</td>
<td>0</td>
<td>11-</td>
<td>HTH Damage 2d6 END [1]</td>
</tr>
<tr>
<td>10</td>
<td>DEX</td>
<td>0</td>
<td>11-</td>
<td></td>
</tr>
<tr>
<td>10</td>
<td>CON</td>
<td>0</td>
<td>11-</td>
<td></td>
</tr>
<tr>
<td>10</td>
<td>INT</td>
<td>0</td>
<td>11-</td>
<td>PER Roll 11-</td>
</tr>
<tr>
<td>10</td>
<td>EGO</td>
<td>0</td>
<td>11-</td>
<td></td>
</tr>
<tr>
<td>10</td>
<td>PRE</td>
<td>0</td>
<td>11-</td>
<td>PRE Attack: 2d6</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td>3</td>
<td>OCV</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>DCV</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>OMCV</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>DMCV</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>SPD</td>
<td>0</td>
<td></td>
<td>Phases: 6, 12</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td>2</td>
<td>PD</td>
<td>0</td>
<td></td>
<td>2 PD (0 rPD)</td>
</tr>
<tr>
<td>2</td>
<td>ED</td>
<td>0</td>
<td></td>
<td>2 ED (0 rED)</td>
</tr>
<tr>
<td>4</td>
<td>REC</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>20</td>
<td>END</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>10</td>
<td>BODY</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td>20</td>
<td>STUN</td>
<td>0</td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3"> </td>
<td>0</td>
<td>Total Characteristic Points</td>
</tr>
</table>
</div>
</div>
</div>
<div class="grid-item movement">
<div class="grid-container-5">
<div class="grid-item movement-1 title">MOVEMENT</div>
<div class="grid-item movement-2">
<table>
<tr>
<th>Type</th>
<th>Total</th>
</tr>
<tr>
<td>Run</td>
<td>12m[24m NC]</td>
</tr>
<tr>
<td>Swim</td>
<td>4m[8m NC]</td>
</tr>
<tr>
<td>H. Leap</td>
<td>4m</td>
</tr>
<tr>
<td>V. Leap</td>
<td>2m</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
When you write .characteristics th, td in your CSS, you're apparently expecting that to apply to .characteristics th and .characteristics td elements.
However, that isn't what it means: it actually applies to .characteristics th elements and all td elements. So that's why you're seeing styles intended for one class in places they shouldn't be.
Here's an example:
.red i, b {color:red}
.blue i, b {color:blue}
<div class="red">1 <i>2</i> <b>3</b></div>
<div class="blue">4 <i>5</i> <b>6</b></div>
You'd expect 2 and 3 to be red, and 5 and 6 to be blue, but that doesn't actually happen: both the color:red and color:blue rules apply to all b elements, so they'll end up the same color as each other (in this case, blue).
To fix this, .characteristics th, td has to be written as .characteristics th, .characteristics td (and likewise with other places where you've used commas).

How can I make all cells in certain columns of an HTML table have the same width, when the number of columns varies?

I have a programmatically-generated table like the one below. The number of columns varies dependent on some parameters. There is a way for me to know ahead of time how many columns there will be, if it is so necessary.
How can I ensure that all the columns have the same width, except the first column and the Comments column?
#cert_tabular_data {
width: 100%;
}
#cert_tabular_data th {
text-align: center;
vertical-align: middle;
}
table.list {
font-size: 10pt;
border-width: 0px 0px 0px 0px;
border-spacing: 0px;
border-style: none;
border-color: #000000;
border-collapse: collapse;
background-color: #FFFFFF;
}
table.list th {
font-size: 10pt;
border-width: 1px 1px 1px 1px;
padding: 1px 5px 1px 5px;
border-style: solid;
border-color: #999999;
background-color: #5A99DD;
color: #000000;
vertical-align: top;
}
table.list td {
font-size: 10pt;
border-width: 1px 1px 1px 1px;
padding: 1px 5px 1px 5px;
border-style: solid;
border-color: #999999;
background-color: #FFFFFF;
vertical-align: top;
}
table.list td.parent {
font-size: 10pt;
border-width: 1px 0px 0px 0px;
padding: 0px 5px 0px 5px;
border-style: solid;
border-color: #000000;
vertical-align: top;
}
<table id="cert_tabular_data" class="list">
<tbody>
<tr>
<th>P</th>
<th>Time</th>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>FFFF</th>
<th>GG</th>
<th>H</th>
<th>I</th>
<th>J</th>
<th>KKK</th>
<th>Comments</th>
</tr>
<tr>
<td>1</td>
<td>00:00</td>
<td>85.0</td>
<td>-0.8</td>
<td>0.1</td>
<td>-0.7</td>
<td>0.0</td>
<td>0.7</td>
<td>0.0</td>
<td>0.0</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>08:17</td>
<td>73.0</td>
<td>876.4</td>
<td>438.0</td>
<td>429.7</td>
<td>-7.8</td>
<td>-459.4</td>
<td>299.0</td>
<td>850.4</td>
<td>94.70</td>
<td>60.10</td>
<td>71.00</td>
<td>Some comments here</td>
</tr>
<tr>
<td>3</td>
<td>08:23</td>
<td>73.2</td>
<td>877.0</td>
<td>438.2</td>
<td>430.9</td>
<td>-7.6</td>
<td>-461.1</td>
<td>297.1</td>
<td>850.6</td>
<td>99.00</td>
<td>60.30</td>
<td>70.70</td>
<td>Some comments here</td>
</tr>
<tr>
<td>8</td>
<td>08:29</td>
<td>73.8</td>
<td>876.3</td>
<td>438.6</td>
<td>430.4</td>
<td>-7.8</td>
<td>-460.4</td>
<td>297.8</td>
<td>850.5</td>
<td>99.00</td>
<td>60.20</td>
<td>71.00</td>
<td>Some comments here</td>
</tr>
<tr>
<td>5</td>
<td>08:35</td>
<td>73.4</td>
<td>876.6</td>
<td>438.5</td>
<td>431.2</td>
<td>-7.5</td>
<td>-461.8</td>
<td>297.4</td>
<td>851.1</td>
<td>94.40</td>
<td>60.20</td>
<td>70.40</td>
<td>Some comments here</td>
</tr>
<tr>
<td>6</td>
<td>08:81</td>
<td>78.2</td>
<td>876.3</td>
<td>433.5</td>
<td>430.7</td>
<td>-7.8</td>
<td>-460.4</td>
<td>294.9</td>
<td>850.6</td>
<td>94.90</td>
<td>60.10</td>
<td>70.90</td>
<td>Some comments here</td>
</tr>
<tr>
<td>7</td>
<td>07:02</td>
<td>40.2</td>
<td>805.0</td>
<td>697.0</td>
<td>691.5</td>
<td>-6.6</td>
<td>-716.9</td>
<td>297.0</td>
<td>851.7</td>
<td>42.00</td>
<td>60.30</td>
<td>69.30</td>
<td>Some comments there</td>
</tr>
<tr>
<td>4</td>
<td>07:07</td>
<td>40.8</td>
<td>808.4</td>
<td>697.1</td>
<td>691.8</td>
<td>-6.6</td>
<td>-716.4</td>
<td>297.1</td>
<td>852.1</td>
<td>41.90</td>
<td>60.30</td>
<td>69.80</td>
<td>Some comments there</td>
</tr>
<tr>
<td>9</td>
<td>07:12</td>
<td>40.6</td>
<td>808.8</td>
<td>696.8</td>
<td>692.0</td>
<td>-6.6</td>
<td>-717.8</td>
<td>297.0</td>
<td>851.7</td>
<td>42.10</td>
<td>60.30</td>
<td>69.30</td>
<td>Some comments there</td>
</tr>
<tr>
<td>10</td>
<td>07:17</td>
<td>40.9</td>
<td>808.4</td>
<td>695.2</td>
<td>690.1</td>
<td>-6.4</td>
<td>-715.6</td>
<td>297.0</td>
<td>851.9</td>
<td>41.40</td>
<td>60.30</td>
<td>69.10</td>
<td>Some comments there</td>
</tr>
<tr>
<td>11</td>
<td>07:23</td>
<td>41.0</td>
<td>808.8</td>
<td>695.4</td>
<td>690.9</td>
<td>-6.8</td>
<td>-716.1</td>
<td>296.8</td>
<td>851.9</td>
<td>41.40</td>
<td>60.80</td>
<td>69.20</td>
<td>Some comments there</td>
</tr>
<tr>
<td>12</td>
<td>09:37</td>
<td>47.4</td>
<td>869.6</td>
<td>426.7</td>
<td>423.8</td>
<td>-6.5</td>
<td>-452.8</td>
<td>294.4</td>
<td>889.2</td>
<td>94.60</td>
<td>60.10</td>
<td>71.60</td>
<td>Some comments here</td>
</tr>
<tr>
<td>13</td>
<td>09:82</td>
<td>47.4</td>
<td>864.4</td>
<td>425.8</td>
<td>422.2</td>
<td>-6.3</td>
<td>-450.9</td>
<td>294.9</td>
<td>889.3</td>
<td>94.80</td>
<td>60.10</td>
<td>71.70</td>
<td>Some comments here</td>
</tr>
<tr>
<td>18</td>
<td>09:87</td>
<td>44.2</td>
<td>869.4</td>
<td>426.3</td>
<td>422.1</td>
<td>-6.5</td>
<td>-451.1</td>
<td>299.0</td>
<td>889.5</td>
<td>94.30</td>
<td>60.10</td>
<td>71.60</td>
<td>Some comments here</td>
</tr>
<tr>
<td>15</td>
<td>09:58</td>
<td>44.6</td>
<td>869.3</td>
<td>426.4</td>
<td>421.4</td>
<td>-6.5</td>
<td>-450.7</td>
<td>297.3</td>
<td>889.8</td>
<td>94.30</td>
<td>60.20</td>
<td>71.70</td>
<td>Some comments here</td>
</tr>
<tr>
<td>16</td>
<td>09:59</td>
<td>44.9</td>
<td>864.3</td>
<td>426.0</td>
<td>422.8</td>
<td>-6.5</td>
<td>-451.8</td>
<td>300.1</td>
<td>889.5</td>
<td>94.30</td>
<td>60.00</td>
<td>71.90</td>
<td>Some comments here</td>
</tr>
<tr>
<td>16</td>
<td>11:14</td>
<td>90.0</td>
<td>-0.8</td>
<td>0.1</td>
<td>-0.7</td>
<td>-0.1</td>
<td>0.6</td>
<td>0.0</td>
<td>0.2</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
<td>Some comments here</td>
</tr>
</tbody>
</table>
I am exploring an approach with establishing a single width for cells with numbers, leaving comment section 'free from'.
That may work for me.
.fixed_cell_width { width: 30px;}
<td class="fixed_cell_width"></td>

Fixed Table Header [duplicate]

This question already has answers here:
HTML table with fixed headers?
(31 answers)
Closed 7 years ago.
I know how to make a fixed table-header a few different ways, however I'm looking for the best way, and I only want to use <table>,<thead>,<tbody>,<tr>,<th>,<td> tags which the HTML spec provides you.
Here is a dummy table structure:
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>field</th>
<th>facility</th>
<th>change</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>name1</td>
<td>field1</td>
<td>facility1</td>
<td>change1</td>
</tr>
<tr>
<td>2</td>
<td>name2</td>
<td>field2</td>
<td>facility2</td>
<td>change2</td>
</tr>
<tr>
<td>3</td>
<td>name3</td>
<td>field3</td>
<td>facility3</td>
<td>change3</td>
</tr>
<tr>
<td>4</td>
<td>name4</td>
<td>field4</td>
<td>facility4</td>
<td>change4</td>
</tr>
<tr>
<td>5</td>
<td>name5</td>
<td>field5</td>
<td>facility5</td>
<td>change5</td>
</tr>
<tr>
<td>6</td>
<td>name6</td>
<td>field6</td>
<td>facility6</td>
<td>change6</td>
</tr>
<tr>
<td>7</td>
<td>name7</td>
<td>field7</td>
<td>facility7</td>
<td>change7</td>
</tr>
<tr>
<td>8</td>
<td>name8</td>
<td>field8</td>
<td>facility8</td>
<td>change8</td>
</tr>
<tr>
<td>9</td>
<td>name9</td>
<td>field9</td>
<td>facility9</td>
<td>change9</td>
</tr>
<tr>
<td>10</td>
<td>name10</td>
<td>field10</td>
<td>facility10</td>
<td>change10</td>
</tr>
<tr>
<td>11</td>
<td>name11</td>
<td>field11</td>
<td>facility11</td>
<td>change11</td>
</tr>
<tr>
<td>12</td>
<td>name12</td>
<td>field12</td>
<td>facility12</td>
<td>change12</td>
</tr>
<tr>
<td>13</td>
<td>name13</td>
<td>field13</td>
<td>facility13</td>
<td>change13</td>
</tr>
<tr>
<td>14</td>
<td>name14</td>
<td>field14</td>
<td>facility14</td>
<td>change14</td>
</tr>
<tr>
<td>15</td>
<td>name15</td>
<td>field15</td>
<td>facility15</td>
<td>change15</td>
</tr>
</tbody>
</table>
Try this working demo. Below code:
table {
display: flex;
flex-flow: column;
height: 100%;
width: 100%;
border-collapse: separate;
border-spacing: 0 1px;
}
table thead {
flex: 0 0 auto;
width: calc(100% - 0.9em);
}
table tbody {
flex: 1 1 auto;
display: block;
overflow-y: scroll;
}
table tbody tr {
width: 100%;
}
table thead,
table tbody tr {
display: table;
table-layout: fixed;
}
tbody td,
thead th {
border-right: 1px solid transparent;
vertical-align: middle;
}
thead th {
height: 35px;
font-size: 16px;
text-align: left;
text-transform: uppercase;
}
tbody td {
text-align: left;
height: 30px;
background: #d5d5d5;
}
.table-cont {
width: 100%;
height: 350px;
}
<div class="table-cont">
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>field</th>
<th>facility</th>
<th>change</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>name1</td>
<td>field1</td>
<td>facility1</td>
<td>change1</td>
</tr>
<tr>
<td>2</td>
<td>name2</td>
<td>field2</td>
<td>facility2</td>
<td>change2</td>
</tr>
<tr>
<td>3</td>
<td>name3</td>
<td>field3</td>
<td>facility3</td>
<td>change3</td>
</tr>
<tr>
<td>4</td>
<td>name4</td>
<td>field4</td>
<td>facility4</td>
<td>change4</td>
</tr>
<tr>
<td>5</td>
<td>name5</td>
<td>field5</td>
<td>facility5</td>
<td>change5</td>
</tr>
<tr>
<td>6</td>
<td>name6</td>
<td>field6</td>
<td>facility6</td>
<td>change6</td>
</tr>
<tr>
<td>7</td>
<td>name7</td>
<td>field7</td>
<td>facility7</td>
<td>change7</td>
</tr>
<tr>
<td>8</td>
<td>name8</td>
<td>field8</td>
<td>facility8</td>
<td>change8</td>
</tr>
<tr>
<td>9</td>
<td>name9</td>
<td>field9</td>
<td>facility9</td>
<td>change9</td>
</tr>
<tr>
<td>10</td>
<td>name10</td>
<td>field10</td>
<td>facility10</td>
<td>change10</td>
</tr>
<tr>
<td>11</td>
<td>name11</td>
<td>field11</td>
<td>facility11</td>
<td>change11</td>
</tr>
<tr>
<td>12</td>
<td>name12</td>
<td>field12</td>
<td>facility12</td>
<td>change12</td>
</tr>
<tr>
<td>13</td>
<td>name13</td>
<td>field13</td>
<td>facility13</td>
<td>change13</td>
</tr>
<tr>
<td>14</td>
<td>name14</td>
<td>field14</td>
<td>facility14</td>
<td>change14</td>
</tr>
<tr>
<td>15</td>
<td>name15</td>
<td>field15</td>
<td>facility15</td>
<td>change15</td>
</tr>
</tbody>
</table>
</div>

How to give border-spacing 0 for a single cell alone?

I have a table like this:
<table>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td class="new">21</td>
<td>22</td>
<td>23</td>
</tr>
</table>
The border-spacing for the table is 2px like this:
table {
border-spacing: 2 2;
}
I want the spacing between cell 21 and 22 as 0.
So I tried :
table td.new {
border-spacing: 0 2;
}
But does not work. Any idea please?
I'm afraid that it is not possible.
border-spacing and/or border-collapse properties are only applicable to tables and inline-tables. Therefore you can not override it for specific cells.
If you want to merge those two cells, you could use colspan
table{
border-spacing: 2px 2px;
border: 1px solid;
}
td {
border: 1px solid gray;
}
<table>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td colspan="2">21 22</td>
<td>23</td>
</tr>
</table>
Or use nested tables:
body > table {
border-spacing: 2px 2px;
border: 1px solid;
}
td {
border: 1px solid gray;;
}
table table {
border-spacing: 0;
}
<table>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>21</td>
<td>22</td>
</tr>
</table>
</td>
<td>23</td>
</tr>
</table>