CSS Highlighting table row and column is not effective - css

I have 4 tables side by side like the one in Highlight column and row in a table ::after and ::before not work
My problem is that, take the table in that question for example, when the mouse goes from c to b or a (or from b to a) the highlight stays at the row with c instead of moving to b or a (stays at the row with b). Basically, it works fine when the mouse goes from upside to downside, but not from downside to the upside.
I am wondering how to fix it. Because I also make the table cell highlighted when it is clicked, and record which cell is highlighted and unhighlighted, so the problem somtimes makes a wrong cell highlighted when clicked, and makes the record somehow biased.
I am testing using Chrome.
Here is an example
th{
font-weight: normal;
align-content: center;
}
td {
border: black solid;
border-width: 1px 2px 1px 1px;
padding: 5px;
text-align: center;
height:1.1cm;
width:1.1cm;
background-clip: padding-box
}
.col {
width: 1.1cm;
}
.rotate {
text-align: center;
white-space: nowrap;
vertical-align: middle;
width: 1.5em;
}
.rotate div {
-moz-transform: rotate(-90.0deg); /* FF3.5+ */
-o-transform: rotate(-90.0deg); /* Opera 10.5 */
-webkit-transform: rotate(-90.0deg); /* Saf3.1+, Chrome */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083); /* IE6,IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083)"; /* IE8 */
margin-left: -1cm;
margin-right: -1cm;
}
.float-left {
width: 25%;
float: left;
}
tr.hl:hover th:not([rowspan]),
tr.hl:hover td {
background-color: rgba(255,255,0,0.25);
}
td:hover::before {
content: '';
position: absolute;
background-color: rgba(255,255,0,0.25);
z-index: 0;
width: 100%;
top: 0;
}
td:hover::after,
.col:hover::after {
content: '';
position: absolute;
background-color: rgba(255,255,0,0.25);
z-index: 0;
height: 2000%;
width: 100%;
bottom: -1000%;
left: 0;
}
th,
td {
position: relative;
}
table{
overflow: hidden;
}
thead th{
background-color:white;
box-shadow: 0 0 0 2px white;
z-index: 1;
}
<div class="g1g2">
<div class="float-left">
<table id="player1" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right" >Player 1's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 2's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">d</th>
<th class="col">e</th>
<th class="col">f</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller;"> <div>Player 1's actions</div></th>
<th>a</th>
<td>8</td>
<td>20</td>
<td>12</td>
</tr>
<tr class="hl">
<th>b</th>
<td>0</td>
<td>8</td>
<td>16</td>
</tr>
<tr class="hl">
<th>c</th>
<td>18</td>
<td>12</td>
<td>6</td>
</tr>
</table>
</div>
</div>
<div class="g1g2">
<div class="float-left">
<table id="player2" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right">Player 2's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 3's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">g</th>
<th class="col">h</th>
<th class="col">i</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller"> <div>Player 2's actions</div></th>
<th>d</th>
<td>14</td>
<td>18</td>
<td>4</td>
</tr>
<tr class="hl">
<th>e</th>
<td>20</td>
<td>14</td>
<td>8</td>
</tr>
<tr class="hl">
<th>f</th>
<td>16</td>
<td>2</td>
<td>18</td>
</tr>
</table>
</div>
</div>
<div class="g1g2">
<div class="float-left">
<table id="player3" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right">Player 3's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 4's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">j</th>
<th class="col">k</th>
<th class="col">l</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller"> <div>Player 3's actions</div></th>
<th>g</th>
<td>20</td>
<td>14</td>
<td>8</td>
</tr>
<tr class="hl">
<th>h</th>
<td>16</td>
<td>2</td>
<td>18</td>
</tr>
<tr class="hl">
<th>i</th>
<td>0</td>
<td>16</td>
<td>16</td>
</tr>
</table>
</div>
</div>
<div class="g1">
<div class="float-left">
<table id="player4a" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right">Player 4's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 1's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">a</th>
<th class="col">b</th>
<th class="col">c</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller"> <div>Player 4's actions</div></th>
<th>j</th>
<td>12</td>
<td>16</td>
<td>14</td>
</tr>
<tr class="hl">
<th>k</th>
<td>8</td>
<td>12</td>
<td>10</td>
</tr>
<tr class="hl">
<th>l</th>
<td>6</td>
<td>10</td>
<td>8</td>
</tr>
</table>
</div>
</div>

Simplest fix would be to add pointer-events: none to ::after and ::before pseudo elements. It also has a great browser support.
Tbh I haven't looked at the code xD, but probably another fix would to be to mess around with z-index which I won't recommend since it can be solved with pointer-events.
th{
font-weight: normal;
align-content: center;
}
td {
border: black solid;
border-width: 1px 2px 1px 1px;
padding: 5px;
text-align: center;
height:1.1cm;
width:1.1cm;
background-clip: padding-box
}
.col {
width: 1.1cm;
}
.rotate {
text-align: center;
white-space: nowrap;
vertical-align: middle;
width: 1.5em;
}
.rotate div {
-moz-transform: rotate(-90.0deg); /* FF3.5+ */
-o-transform: rotate(-90.0deg); /* Opera 10.5 */
-webkit-transform: rotate(-90.0deg); /* Saf3.1+, Chrome */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083); /* IE6,IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083)"; /* IE8 */
margin-left: -1cm;
margin-right: -1cm;
}
.float-left {
width: 25%;
float: left;
}
tr.hl:hover th:not([rowspan]),
tr.hl:hover td {
background-color: rgba(255,255,0,0.25);
}
td:hover::before {
content: '';
position: absolute;
background-color: rgba(255,255,0,0.25);
z-index: 0;
width: 100%;
top: 0;
}
td:hover::after,
.col:hover::after {
content: '';
position: absolute;
background-color: rgba(255,255,0,0.25);
z-index: 0;
height: 2000%;
width: 100%;
bottom: -1000%;
left: 0;
pointer-events: none;
}
th,
td {
position: relative;
}
table{
overflow: hidden;
}
thead th{
background-color:white;
box-shadow: 0 0 0 2px white;
z-index: 1;
}
<div class="g1g2">
<div class="float-left">
<table id="player1" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right" >Player 1's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 2's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">d</th>
<th class="col">e</th>
<th class="col">f</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller;"> <div>Player 1's actions</div></th>
<th>a</th>
<td>8</td>
<td>20</td>
<td>12</td>
</tr>
<tr class="hl">
<th>b</th>
<td>0</td>
<td>8</td>
<td>16</td>
</tr>
<tr class="hl">
<th>c</th>
<td>18</td>
<td>12</td>
<td>6</td>
</tr>
</table>
</div>
</div>
<div class="g1g2">
<div class="float-left">
<table id="player2" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right">Player 2's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 3's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">g</th>
<th class="col">h</th>
<th class="col">i</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller"> <div>Player 2's actions</div></th>
<th>d</th>
<td>14</td>
<td>18</td>
<td>4</td>
</tr>
<tr class="hl">
<th>e</th>
<td>20</td>
<td>14</td>
<td>8</td>
</tr>
<tr class="hl">
<th>f</th>
<td>16</td>
<td>2</td>
<td>18</td>
</tr>
</table>
</div>
</div>
<div class="g1g2">
<div class="float-left">
<table id="player3" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right">Player 3's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 4's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">j</th>
<th class="col">k</th>
<th class="col">l</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller"> <div>Player 3's actions</div></th>
<th>g</th>
<td>20</td>
<td>14</td>
<td>8</td>
</tr>
<tr class="hl">
<th>h</th>
<td>16</td>
<td>2</td>
<td>18</td>
</tr>
<tr class="hl">
<th>i</th>
<td>0</td>
<td>16</td>
<td>16</td>
</tr>
</table>
</div>
</div>
<div class="g1">
<div class="float-left">
<table id="player4a" style="margin-bottom: 1cm">
<thead>
<tr>
<th colspan=5 style="text-align: right">Player 4's Payoffs </th>
</tr>
<tr>
<th colspan=2 rowspan=2></th>
<th colspan=3 style="font-size: smaller; text-align: center">Player 1's actions</th>
</tr>
</thead>
<tr style="text-align: center">
<th colspan="2"></th>
<th class="col">a</th>
<th class="col">b</th>
<th class="col">c</th>
</tr>
<tr class="hl">
<th rowspan=3 class="rotate" style="font-size: smaller"> <div>Player 4's actions</div></th>
<th>j</th>
<td>12</td>
<td>16</td>
<td>14</td>
</tr>
<tr class="hl">
<th>k</th>
<td>8</td>
<td>12</td>
<td>10</td>
</tr>
<tr class="hl">
<th>l</th>
<td>6</td>
<td>10</td>
<td>8</td>
</tr>
</table>
</div>
</div>

Related

Is it possible to set the background of individual lines inside a single table cell?

I wrote some CGI script that outputs a table with variable information.
One of the table cell can contain multiple strings, and I put each on a separate line by joining the strings with <br/>.
Then I thought it would improve readability if every second of such lines would have a different background color (I did that for complete table rows successfully).
So before joining them with <br/> I wrapped the strings in a <span> with alternating class names (like re for "row even" and ro for "row odd").
That worked, but the background end where the text ends, and not where the table cell ends.
Is it possible to set the background for the whole <td> line without putting a <table> inside the <td>?
The current output looks like this:
And the corresponding HTML fragement is (most styling is done via CSS):
<table class="inf-tbl" summary="Server Information" title="Server Information" border="1"><caption class="inf-tbl">Server Information</caption>
<thead><tr><th colspan="2" class="inf-th">(redacted)</th></tr> <tr><th class="inf-th">Kategorie</th> <th class="inf-th">Eigenschaften</th></tr></thead>
<tbody><tr><th class="inf-th">TLS Cipher</th><td class="inf-td">AES256-GCM-SHA384</td>
</tr> <tr><th class="inf-th">Unterstützte LDAP-Versionen</th><td class="inf-td"><span class="re">3</span></td>
</tr> <tr><th class="inf-th">Unterstützte Controls</th><td class="inf-td"><span class="ro">MANAGEDSAIT</span></td>
</tr> <tr><th class="inf-th">Unterstützte Features</th><td class="inf-td"><span class="re">ALL_OPATTS</span><br><span class="ro">MODIFY_INCREMENT</span></td>
</tr> <tr><th class="inf-th">Unterstützte Extensions</th><td class="inf-td"><span class="re">PASSWORD_MODIFY</span><br><span class="ro">START_TLS</span><br><span class="re">WHO_AM_I</span></td>
</tr> <tr><th class="inf-th">Unterstützte SASL-Mechanismen</th><td class="inf-td"><span class="ro">DIGEST-MD5</span><br><span class="re">GSSAPI</span></td>
</tr></tbody>
</table>
Revision 1
With the suggestions from https://stackoverflow.com/a/74447412/6607497 I got this (note: I tweaked the left columns also to apply alternating background):
The updated HTML code is this (re and ro are "row even" and "row odd", and l means "apply to whole 'line'"; there are some other classes that can be ignored):
<table title="Server Information" summary="Server Information" class="inf-tbl" border="1"><caption class="inf-tbl">Server Information</caption>
<thead><tr><th colspan="2" class="inf-th">(redacted)</th></tr> <tr><th class="inf-th">Kategorie</th> <th class="inf-th">Eigenschaften</th></tr></thead>
<tbody><tr><th class="inf-th">TLS Cipher</th><td class="inf-td">AES256-GCM-SHA384</td>
</tr> <tr><th class="inf-th ro">Unterstützte LDAP-Versionen</th><td class="inf-td"><span class="l ro">3</span></td>
</tr> <tr><th class="inf-th re">Unterstützte Controls</th><td class="inf-td"><span class="l re">MANAGEDSAIT</span></td>
</tr> <tr><th class="inf-th ro">Unterstützte Features</th><td class="inf-td"><span class="l ro">ALL_OPATTS</span><br><span class="l re">MODIFY_INCREMENT</span></td>
</tr> <tr><th class="inf-th re">Unterstützte Extensions</th><td class="inf-td"><span class="l ro">PASSWORD_MODIFY</span><br><span class="l re">START_TLS</span><br><span class="l ro">WHO_AM_I</span></td>
</tr> <tr><th class="inf-th ro">Unterstützte SASL-Mechanismen</th><td class="inf-td"><span class="l re">DIGEST-MD5</span><br><span class="l ro">GSSAPI</span></td>
</tr></tbody>
</table>
Finally there's the relevant CSS (I'm not good in CSS, obviously):
table {
background-color: white; color: black; margin-top: 1ex; margin-bottom: 1ex
}
td { padding-left: 1mm; padding-right: 1mm }
caption { caption-side: bottom; background-color: #c7ffc7 }
.l { display: inline-block; width: 100%; box-sizing: border-box;} /* fill whole line in cell */
.re, .ef-re, .ds-re { background-color: #e0e3e4 } /* 90% grey */
.ro, .ef-ro, .ds-ro { background-color: #ffffff }
table.inf-tbl { border-style: solid; border-width: thin;
border-collapse: collapse }
.inf-td { padding-left: 0.5ex; padding-right: 0.5ex; font-family: sans-serif;
vertical-align: top
}
.inf-th { padding-left: 0.5ex; padding-right: 0.5ex; font-weight: bolder;
font-family: sans-serif; text-align: left; vertical-align: top
}
Just add the following to your CSS. It makes the span behave as an inline block that you can then set the width to the cell width.
.re,
.ro {
width: 100%;
display: inline-block;
}
.re {
background-color: gray;
}
.ro {
background-color: yellow;
}
<table class="inf-tbl" summary="Server Information" title="Server Information" border="1">
<caption class="inf-tbl">Server Information</caption>
<thead>
<tr>
<th colspan="2" class="inf-th">(redacted)</th>
</tr>
<tr>
<th class="inf-th">Kategorie</th>
<th class="inf-th">Eigenschaften</th>
</tr>
</thead>
<tbody>
<tr>
<th class="inf-th">TLS Cipher</th>
<td class="inf-td">AES256-GCM-SHA384</td>
</tr>
<tr>
<th class="inf-th">Unterstützte LDAP-Versionen</th>
<td class="inf-td"><span class="re">3</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte Controls</th>
<td class="inf-td"><span class="ro">MANAGEDSAIT</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte Features</th>
<td class="inf-td"><span class="re">ALL_OPATTS</span><br><span class="ro">MODIFY_INCREMENT</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte Extensions</th>
<td class="inf-td"><span class="re">PASSWORD_MODIFY</span><br><span class="ro">START_TLS</span><br><span class="re">WHO_AM_I</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte SASL-Mechanismen</th>
<td class="inf-td"><span class="ro">DIGEST-MD5</span><br><span class="re">GSSAPI</span></td>
</tr>
</tbody>
</table>
Update 16 Nov 2022 to ensure padding is respected just add box-sizing:border-box. Example with some random padding added.
.re,
.ro {
box-sizing: border-box;
width: 100%;
display: inline-block;
}
.re {
padding-left: 5px;
padding-right: 8px;
background-color: gray;
}
.ro {
padding-left: 10px;
padding-right: 15px;
background-color: yellow;
}
<table class="inf-tbl" summary="Server Information" title="Server Information" border="1">
<caption class="inf-tbl">Server Information</caption>
<thead>
<tr>
<th colspan="2" class="inf-th">(redacted)</th>
</tr>
<tr>
<th class="inf-th">Kategorie</th>
<th class="inf-th">Eigenschaften</th>
</tr>
</thead>
<tbody>
<tr>
<th class="inf-th">TLS Cipher</th>
<td class="inf-td">AES256-GCM-SHA384</td>
</tr>
<tr>
<th class="inf-th">Unterstützte LDAP-Versionen</th>
<td class="inf-td"><span class="re">3</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte Controls</th>
<td class="inf-td"><span class="ro">MANAGEDSAIT</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte Features</th>
<td class="inf-td"><span class="re">ALL_OPATTS</span><br><span class="ro">MODIFY_INCREMENT</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte Extensions</th>
<td class="inf-td"><span class="re">PASSWORD_MODIFY</span><br><span class="ro">START_TLS</span><br><span class="re">WHO_AM_I</span></td>
</tr>
<tr>
<th class="inf-th">Unterstützte SASL-Mechanismen</th>
<td class="inf-td"><span class="ro">DIGEST-MD5</span><br><span class="re">GSSAPI</span></td>
</tr>
</tbody>
</table>

Table css is messing up on shrinking the window

My code is working fine and displaying the tables with css well applied but when I am shrinking the window table is getting messed up with different columns taking up different space (I have attached in screenshot). Basically I want the first column which is without the checkbox to be intact(sticky) and rest columns to take equal space with a scroll enabled when I shrink the window . How do I fix that up, Can anyone please help?
Is there any way I keep the table container width as it is there in desktop view and just put a scroller in the mobile view with first column fixed and not shrink the tables?
like in this example https://codepen.io/paulobrien/pen/LBrMxa
.hero-button {
padding: 27px;
cursor: pointer;
text-decoration: none !important;
}
a .hero-button1 {
min-height: 36px;
letter-spacing: normal;
border-width: 2px;
border-style: solid;
border-color: rgb(255, 255, 255);
border-image: initial;
border-radius: 25px;
padding: 6px 50px;
text-decoration: none;
display: inline-block;
font-size: 14px;
color: #fff;
font-weight: 600;
letter-spacing: 3px;
margin: 35px 0 0;
}
input {
color: black;
}
.table_container {
float: left;
width: 30rem;
margin-bottom: 3rem;
}
.table_container2 {
float: left;
width: 30rem;
margin-bottom: 3rem;
}
.container {
width: 100%;
margin-top: 30px;
display: flex;
justify-content: center
}
.container2 {
display: flex;
justify-content: center;
}
.checkcontainer {
width: 100%;
}
.container::after {
content: "";
clear: both;
display: table;
}
table {
margin: 2rem auto;
border-radius: 10px;
}
tr {
padding: 15px;
text-align: center;
}
td {
color: black;
text-align: center;
vertical-align: middle;
height: 60px;
background-color: #e1edf9;
width: 272px;
border-top: 1px solid white;
}
.sub_text {
font-size: 12px;
font-style: italic;
color: #003a6a;
font-weight: 100;
}
th {
background-color: #003a6a;
text-align: center;
padding: 0px 10px 0px 10px;
/*border-top-left-radius: 10px;*/
/*border-top-right-radius: 10px;*/
color: white;
font-weight: bold;
height: 75px;
}
.header {
color: #003a6a;
font-weight: bold;
padding: 10px;
border-right: 1px solid white;
}
.wrapper {
margin-top: 20px;
display: flex;
justify-content: center;
}
.modal-content {
top: 50% !important;
position: fixed !important;
}
table tr:last-child td:first-child {
/*border-bottom-left-radius: 10px;*/
}
table tr:last-child td:last-child {
/* border-bottom-right-radius: 10px;*/
}
#media screen and (min-width: 1400px) {
.table_container {
float: left;
width: 15rem;
}
.table_container:first-of-type {
width: 30rem;
}
}
#media screen and (min-width: 1400px) {
.table_container2 {
float: left;
width: 15rem;
}
.table_container2:first-of-type {
width: 30rem;
}
}
#media only screen and (min-width: 1000) and (max-device-width: 1400px) {
.table_container2 {
float: left;
width: 14rem;
}
.table_container2:first-of-type {
width: 27rem;
}
}
#media only screen and (min-width: 1000) and (max-device-width: 1400px) {
.table_container {
float: left;
width: 14rem;
}
.table_container:first-of-type {
width: 27rem;
}
}
.checks {
height: 20px;
background-color: #003A6A;
border-top: none;
}
.parent_container {
width: 100%;
text-align: center;
}
#modalButton {
background-color: #003A6A;
}
<div class="parent_container">
<div class="container">
<div class="table_container">
<table>
<thead>
<tr>
<th colspan="2">Cost</th>
</tr>
<tr>
</thead>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + Spouse/partner</td>
</tr>
<tr>
<td>employee + child(ren)</td>
</tr>
<tr>
<td>employee + family</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual max contribution<br>
<span class="sub_text">
</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual out-of-pocket maximum<br>
<span class="sub_text">in-network care</span>
</td>
<td>Per person</td>
<tr>
<td>Entire family</td>
</tr>
</tr>
</table>
</div>
<div class="table_container">
<table id="table1" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW <input type="checkbox" id=" 1" name="table1" value="table1"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$133.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>$4 after deductible
$50 or 25% of allowed cost* after deductible</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$50 or 20% of allowed cost* after deductible
</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$6650</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan <input type="checkbox" id="2" name="table2" value="table2"
onchange="myFunction(event)"></th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table3" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan SW <input type="checkbox" id="3" name="table3" value="table3"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$60</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$10</td>
</tr>
</table>
</div>
</div>
<div class="container2">
<div class="table_container">
<table>
<thead>
<tr>
<th colspan="2">Cost</th>
</tr>
<tr>
</thead>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + Spouse/partner</td>
</tr>
<tr>
<td>employee + child(ren)</td>
</tr>
<tr>
<td>employee + family</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual max contribution<br>
<span class="sub_text">
</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual out-of-pocket maximum<br>
<span class="sub_text">in-network care</span>
</td>
<td>Per person</td>
<tr>
<td>Entire family</td>
</tr>
</tr>
</table>
</div>
<div class="table_container">
<table id="table1" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW Arkansas <input type="checkbox" id=" 1" name="table1" value="table1"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$133.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$6650</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW Arkansas <input type="checkbox" id="2" name="table2" value="table2"
onchange="myFunction(event)"></th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table3" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW Arkansas <input type="checkbox" id="3" name="table3" value="table3"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$60</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$10</td>
</tr>
</table>
</div>
</div>
<div class="wrapper">
<button type="button" id="modalButton" class="btn btn-primary" data-toggle="modal" data-target="#myModal" onclick="javascript: return false;" >
Click me
</button>
</div>
</div>
I made the table responsive in such a way that when the screen size reduces the table would retain its original dimensions but the scrollbar would appear in x and y directions(Thats what I read in your comment) I just did this for one table.
What I did was encapsulate the .container class with .parent_container
and gave it following css
.parent_container{
max-width: 844px;
height: 733px;
overflow:auto;
width: 100%;
}
here I calculated the width and height of .parent_container by using inspect tool.
Also I provided a min-width to the table so that the it won't shrink when screen size reduces.
This will work for u
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
}
.parent_container {
max-height: 1164px;
max-width: 1181px;
width: 90%;
overflow: auto;
margin: 0px 20px;
padding: 5px 0;
}
table {
border-collapse: collapse;
}
td,
th {
border: 1px solid white;
padding: 20px 10px;
min-width: 220px;
text-align: center;
}
.left_column td {
min-width: 110px;
}
td {
background: #E1EDF9;
}
th {
background: #003A6A;
color: white;
font-size: 18px;
position: sticky;
top: 0;
}
.left_column {
position: sticky;
width: 250px;
left: 0;
}
.side_header {
color: #003A6A;
font-weight: bold;
font-size: 20px;
}
.side_header span {
font-weight: normal;
}
span {
display: block;
font-size: 12px;
}
tr table tr td {
min-width: 220px;
}
<div class="parent_container">
<table>
<thead>
<tr>
<th colspan="2" style="position: sticky;left: 0;z-index: 10000;">
Cost
</th>
<th>
Saver Plan NW
<input type="checkbox" name="">
</th>
<th>
Saver Plan
<input type="checkbox" name="">
</th>
<th>
Saver Plan SW
<input type="checkbox" name="">
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="left_column" colspan="2" rowspan="4" style="padding: 0px">
<table style="">
<tr>
<td rowspan="5" class="side_header">
Your cost per biweekly paycheck <span>Tobacco-free rates shown</span>
</td>
</tr>
<tr>
<td>employee Only</td>
</tr>
<tr>
<td>employee + Spouse/partner</td>
</tr>
<tr>
<td>employee + child(ren)</td>
</tr>
<tr>
<td>employee + family</td>
</tr>
</table>
</td>
<td>$133.90</td>
<td>$33.90</td>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
<td>$161.30</td>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
<td>$53.30</td>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
<td>$186.20</td>
<td>$186.20</td>
</tr>
<tr>
<td class="left_column" colspan="2" rowspan="2" style="padding: 0px;">
<table>
<tr>
<td rowspan="3" class="side_header">
Annual max contribution
</td>
</tr>
<tr>
<td style="padding-top: 30px">employee Only</td>
</tr>
<tr>
<td style="padding-bottom: 30px">employee + dependent(s)</td>
</tr>
</table>
</td>
<td>$4 after deductible $50 or 25% of allowed cost* after deductible</td>
<td>HSA match:up to $350</td>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td class="left_column" colspan="2" rowspan="2" style="padding: 0px;">
<table>
<tr>
<td rowspan="3" class="side_header">
Annua deductible<span>in-network care</span>
</td>
</tr>
<tr>
<td style="padding-top: 30px">employee Only</td>
</tr>
<tr>
<td style="padding-top: 30px">employee + dependent(s)</td>
</tr>
</table>
</td>
<td>$50 or 20% of allowed cost* after deductible</td>
<td>$3000</td>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
<td>$6000</td>
<td>$60</td>
</tr>
<tr>
<td class="left_column" colspan="2" rowspan="2" style="padding: 0px;">
<table>
<tr>
<td rowspan="3" class="side_header">
Annual out-of-pocket maximum <span>in-network care</span>
</td>
</tr>
<tr>
<td>Per person</td>
</tr>
<tr>
<td>Entire family</td>
</tr>
</table>
</td>
<td>$6650</td>
<td>$660</td>
<td>$660</td>
</tr>
<tr>
<td>$13300</td>
<td>$13300</td>
<td>$10</td>
</tr>
</tbody>
</table>
</div>
<div class="parent_container">
<table>
<thead>
<tr>
<th colspan="2" style="position: sticky;left: 0;z-index: 10000;">
Cost
</th>
<th>
Saver Plan NW
<input type="checkbox" name="">
</th>
<th>
Saver Plan
<input type="checkbox" name="">
</th>
<th>
Saver Plan SW
<input type="checkbox" name="">
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="left_column" colspan="2" rowspan="4" style="padding: 0px">
<table style="">
<tr>
<td rowspan="5" class="side_header">
Your cost per biweekly paycheck <span>Tobacco-free rates shown</span>
</td>
</tr>
<tr>
<td>employee Only</td>
</tr>
<tr>
<td>employee + Spouse/partner</td>
</tr>
<tr>
<td>employee + child(ren)</td>
</tr>
<tr>
<td>employee + family</td>
</tr>
</table>
</td>
<td>$133.90</td>
<td>$33.90</td>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
<td>$161.30</td>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
<td>$53.30</td>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
<td>$186.20</td>
<td>$186.20</td>
</tr>
<tr>
<td class="left_column" colspan="2" rowspan="2" style="padding: 0px;">
<table>
<tr>
<td rowspan="3" class="side_header">
Annual max contribution
</td>
</tr>
<tr>
<td style="padding-top: 30px">employee Only</td>
</tr>
<tr>
<td style="padding-bottom: 30px">employee + dependent(s)</td>
</tr>
</table>
</td>
<td>$4 after deductible $50 or 25% of allowed cost* after deductible</td>
<td>HSA match:up to $350</td>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td class="left_column" colspan="2" rowspan="2" style="padding: 0px;">
<table>
<tr>
<td rowspan="3" class="side_header">
Annua deductible<span>in-network care</span>
</td>
</tr>
<tr>
<td style="padding-top: 30px">employee Only</td>
</tr>
<tr>
<td style="padding-top: 30px">employee + dependent(s)</td>
</tr>
</table>
</td>
<td>$50 or 20% of allowed cost* after deductible</td>
<td>$3000</td>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
<td>$6000</td>
<td>$60</td>
</tr>
<tr>
<td class="left_column" colspan="2" rowspan="2" style="padding: 0px;">
<table>
<tr>
<td rowspan="3" class="side_header">
Annual out-of-pocket maximum <span>in-network care</span>
</td>
</tr>
<tr>
<td>Per person</td>
</tr>
<tr>
<td>Entire family</td>
</tr>
</table>
</td>
<td>$6650</td>
<td>$660</td>
<td>$660</td>
</tr>
<tr>
<td>$13300</td>
<td>$13300</td>
<td>$10</td>
</tr>
</tbody>
</table>
</div>
So a lot of your problems came from using CSS versus HTML to format what you're table looked like. If you put it all into one table and then use CSS to enhance it, you run into a lot less problems. I redid your HTML and used the same CSS and it works fine. You will most likely want to remove a lot of those styles because they aren't necessary.
DEMO:
.hero-button {
padding: 27px;
cursor: pointer;
text-decoration: none !important;
}
a .hero-button1 {
min-height: 36px;
letter-spacing: normal;
border-width: 2px;
border-style: solid;
border-color: rgb(255, 255, 255);
border-image: initial;
border-radius: 25px;
padding: 6px 50px;
text-decoration: none;
display: inline-block;
font-size: 14px;
color: #fff;
font-weight: 600;
letter-spacing: 3px;
margin: 35px 0 0;
}
input {
color: black;
}
.table_container {
float: left;
width: 30rem;
margin-bottom: 3rem;
}
.table_container2 {
float: left;
width: 30rem;
margin-bottom: 3rem;
}
.container {
width: 100%;
margin-top: 30px;
display: flex;
justify-content: center
}
.container2 {
display: flex;
justify-content: center;
}
.checkcontainer {
width: 100%;
}
.container::after {
content: "";
clear: both;
display: table;
}
table {
margin: 2rem auto;
border-radius: 10px;
}
tr {
padding: 15px;
text-align: center;
}
td {
color: black;
text-align: center;
vertical-align: middle;
height: 60px;
background-color: #e1edf9;
width: 272px;
border-top: 1px solid white;
}
.sub_text {
font-size: 12px;
font-style: italic;
color: #003a6a;
font-weight: 100;
}
th {
background-color: #003a6a;
text-align: center;
padding: 0px 10px 0px 10px;
/*border-top-left-radius: 10px;*/
/*border-top-right-radius: 10px;*/
color: white;
font-weight: bold;
height: 75px;
}
.header {
color: #003a6a;
font-weight: bold;
padding: 10px;
border-right: 1px solid white;
}
.wrapper {
margin-top: 20px;
display: flex;
justify-content: center;
}
.modal-content {
top: 50% !important;
position: fixed !important;
}
table tr:last-child td:first-child {
/*border-bottom-left-radius: 10px;*/
}
table tr:last-child td:last-child {
/* border-bottom-right-radius: 10px;*/
}
#media screen and (min-width: 1400px) {
.table_container {
float: left;
width: 15rem;
}
.table_container:first-of-type {
width: 30rem;
}
}
#media screen and (min-width: 1400px) {
.table_container2 {
float: left;
width: 15rem;
}
.table_container2:first-of-type {
width: 30rem;
}
}
#media only screen and (min-width: 1000) and (max-device-width: 1400px) {
.table_container2 {
float: left;
width: 14rem;
}
.table_container2:first-of-type {
width: 27rem;
}
}
#media only screen and (min-width: 1000) and (max-device-width: 1400px) {
.table_container {
float: left;
width: 14rem;
}
.table_container:first-of-type {
width: 27rem;
}
}
.checks {
height: 20px;
background-color: #003A6A;
border-top: none;
}
.parent_container {
width: 100%;
text-align: center;
}
#modalButton {
background-color: #003A6A;
margin: 0 auto;
display: block;
}
<table>
<thead>
<tr>
<th colspan="2">Cost
</th>
<th>Saver Plan NW <input type="checkbox" id="1" name="table1" value="table1" onchange="myFunction(event)">
</th>
<th>Saver Plan <input type="checkbox" id="2" name="table2" value="table2" onchange="myFunction(event)">
</th>
<th>Saver Plan SW <input type="checkbox" id="3" name="table3" value="table3" onchange="myFunction(event)">
</th>
</tr>
</thead>
<tr>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td>employee Only</td>
<td>$133.90</td>
<td>$33.90</td>
<td>$33.90</td>
</tr>
<tr>
<td>employee + Spouse/partner</td>
<td>$161.30</td>
<td>$161.30</td>
<td>$161.30</td>
</tr>
<tr>
<td>employee + child(ren)</td>
<td>$53.30</td>
<td>$53.30</td>
<td>$53.30</td>
</tr>
<tr>
<td>employee + family</td>
<td>$186.20</td>
<td>$186.20</td>
<td>$186.20</td>
</tr>
<tr>
<td class="header" rowspan="2">Annual max contribution<br>
<span class="sub_text">
</span>
<td>employee Only</td>
<td>$4 after deductible $50 or 25% of allowed cost* after deductible</td>
<td>HSA match:up to $350</td>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>employee + dependent(s)</td>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td>employee Only</td>
<td>$50 or 20% of allowed cost* after deductible</td>
<td>$3000</td>
<td>$3000</td>
</tr>
<tr>
<td>employee + dependent(s)</td>
<td>$6000</td>
<td>$6000</td>
<td>$60</td>
</tr>
<tr>
<td class="header" rowspan="2">Annual out-of-pocket maximum<br>
<span class="sub_text">in-network care</span>
</td>
<td>Per person</td>
<td>$6650</td>
<td>$660</td>
<td>$660</td>
</tr>
<tr>
<td>Entire family</td>
<td>$13300</td>
<td>$13300</td>
<td>$10</td>
</tr>
</table>
<table>
<thead>
<tr>
<th colspan="2">Cost
</th>
<th>Saver Plan NW Arkansas <input type="checkbox" id="1" name="table1" value="table1"
onchange="myFunction(event)">
</th>
<th>Saver Plan NW Arkansas <input type="checkbox" id="2" name="table2" value="table2"
onchange="myFunction(event)">
</th>
<th>Saver Plan NW Arkansas <input type="checkbox" id="3" name="table3" value="table3"
onchange="myFunction(event)">
</th>
</tr>
</thead>
<tr>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td>employee Only</td>
<td>$133.90</td>
<td>$33.90</td>
<td>$33.90</td>
</tr>
<tr>
<td>employee + Spouse/partner</td>
<td>$161.30</td>
<td>$161.30</td>
<td>$161.30</td>
</tr>
<tr>
<td>employee + child(ren)</td>
<td>$53.30</td>
<td>$53.30</td>
<td>$53.30</td>
</tr>
<tr>
<td>employee + family</td>
<td>$186.20</td>
<td>$186.20</td>
<td>$186.20</td>
</tr>
<tr>
<td class="header" rowspan="2">Annual max contribution<br>
<span class="sub_text">
</span>
<td>employee Only</td>
<td>HSA match:up to $350</td>
<td>HSA match:up to $350</td>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>employee + dependent(s)</td>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td>employee Only</td>
<td>$3000</td>
<td>$3000</td>
<td>$3000</td>
</tr>
<tr>
<td>employee + dependent(s)</td>
<td>$6000</td>
<td>$6000</td>
<td>$60</td>
</tr>
<tr>
<td class="header" rowspan="2">Annual out-of-pocket maximum<br>
<span class="sub_text">in-network care</span>
</td>
<td>Per person</td>
<td>$6650</td>
<td>$660</td>
<td>$660</td>
</tr>
<tr>
<td>Entire family</td>
<td>$13300</td>
<td>$13300</td>
<td>$10</td>
</tr>
</table>
You cannot do much only with css as you are trying to make 4 table fit next to each other.
I would recommand you to use jQuery. After you can add this code in readyand resize event to make sure that the height will be adapted correctly.
Demo:
var highestThead;
var arrayTR = [];
$(window).resize(resizeHeight);
$(document).ready(resizeHeight);
function resizeHeight(){
/* Loop to get the highest tr and store it to the array */
$(".table_container").each(function(){
if($(this).find("thead tr").innerHeight() > highestThead){
highestThead = $(this).find("thead tr").innerHeight();
}
var allTR = $(this).find("tbody tr");
for (i = 0; i < allTR.length; i++) {
if(arrayTR[i] == undefined || $(allTR[i]).innerHeight() > arrayTR[i]){
arrayTR[i] = $(allTR[i]).innerHeight();
}
}
});
/* Loop to set the highest tr to the whole tr */
$(".table_container").each(function(){
$(this).find("thead tr").css("height", highestThead+"px");
var allTR = $(this).find("tbody tr");
for (i = 0; i < allTR.length; i++) {
$(allTR[i]).css("height", arrayTR[i]+"px");
}
});
}
.hero-button {
padding: 27px;
cursor: pointer;
text-decoration: none !important;
}
a .hero-button1 {
min-height: 36px;
letter-spacing: normal;
border-width: 2px;
border-style: solid;
border-color: rgb(255, 255, 255);
border-image: initial;
border-radius: 25px;
padding: 6px 50px;
text-decoration: none;
display: inline-block;
font-size: 14px;
color: #fff;
font-weight: 600;
letter-spacing: 3px;
margin: 35px 0 0;
}
input {
color: black;
}
.table_container {
float: left;
width: 30rem;
margin-bottom: 3rem;
}
.table_container2 {
float: left;
width: 30rem;
margin-bottom: 3rem;
}
.container {
width: 100%;
margin-top: 30px;
display: flex;
justify-content: center
}
.container2 {
display: flex;
justify-content: center;
}
.checkcontainer {
width: 100%;
}
.container::after {
content: "";
clear: both;
display: table;
}
table {
margin: 2rem auto;
border-radius: 10px;
}
tr {
padding: 15px;
text-align: center;
}
td {
color: black;
text-align: center;
vertical-align: middle;
height: 60px;
background-color: #e1edf9;
width: 272px;
border-top: 1px solid white;
}
.sub_text {
font-size: 12px;
font-style: italic;
color: #003a6a;
font-weight: 100;
}
th {
background-color: #003a6a;
text-align: center;
padding: 0px 10px 0px 10px;
/*border-top-left-radius: 10px;*/
/*border-top-right-radius: 10px;*/
color: white;
font-weight: bold;
height: 75px;
}
.header {
color: #003a6a;
font-weight: bold;
padding: 10px;
border-right: 1px solid white;
}
.wrapper {
margin-top: 20px;
display: flex;
justify-content: center;
}
.modal-content {
top: 50% !important;
position: fixed !important;
}
table tr:last-child td:first-child {
/*border-bottom-left-radius: 10px;*/
}
table tr:last-child td:last-child {
/* border-bottom-right-radius: 10px;*/
}
#media screen and (min-width: 1400px) {
.table_container {
float: left;
width: 15rem;
}
.table_container:first-of-type {
width: 30rem;
}
}
#media screen and (min-width: 1400px) {
.table_container2 {
float: left;
width: 15rem;
}
.table_container2:first-of-type {
width: 30rem;
}
}
#media only screen and (min-width: 1000) and (max-device-width: 1400px) {
.table_container2 {
float: left;
width: 14rem;
}
.table_container2:first-of-type {
width: 27rem;
}
}
#media only screen and (min-width: 1000) and (max-device-width: 1400px) {
.table_container {
float: left;
width: 14rem;
}
.table_container:first-of-type {
width: 27rem;
}
}
.checks {
height: 20px;
background-color: #003A6A;
border-top: none;
}
.parent_container {
width: 100%;
text-align: center;
}
#modalButton {
background-color: #003A6A;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent_container">
<div class="container">
<div class="table_container">
<table>
<thead>
<tr>
<th colspan="2">Cost</th>
</tr>
</thead>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + Spouse/partner</td>
</tr>
<tr>
<td>employee + child(ren)</td>
</tr>
<tr>
<td>employee + family</td>
</tr>
<tr>
<td class="header" rowspan="2">Annual max contribution<br>
<span class="sub_text">
</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual out-of-pocket maximum<br>
<span class="sub_text">in-network care</span>
</td>
<td>Per person</td>
<tr>
<td>Entire family</td>
</tr>
</tr>
</table>
</div>
<div class="table_container">
<table id="table1" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW <input type="checkbox" id=" 1" name="table1" value="table1"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$133.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>$4 after deductible
$50 or 25% of allowed cost* after deductible</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$50 or 20% of allowed cost* after deductible
</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$6650</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan <input type="checkbox" id="2" name="table2" value="table2"
onchange="myFunction(event)"></th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table3" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan SW <input type="checkbox" id="3" name="table3" value="table3"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$60</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$10</td>
</tr>
</table>
</div>
</div>
<div class="container2">
<div class="table_container">
<table>
<thead>
<tr>
<th colspan="2">Cost</th>
</tr>
<tr>
</thead>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + Spouse/partner</td>
</tr>
<tr>
<td>employee + child(ren)</td>
</tr>
<tr>
<td>employee + family</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual max contribution<br>
<span class="sub_text">
</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td>employee Only</td>
<tr>
<td>employee + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annual out-of-pocket maximum<br>
<span class="sub_text">in-network care</span>
</td>
<td>Per person</td>
<tr>
<td>Entire family</td>
</tr>
</tr>
</table>
</div>
<div class="table_container">
<table id="table1" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW Arkansas <input type="checkbox" id=" 1" name="table1" value="table1"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$133.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$6650</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW Arkansas <input type="checkbox" id="2" name="table2" value="table2"
onchange="myFunction(event)"></th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$6000</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$13300</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table3" class="checkboxdiv">
<thead>
<tr>
<th>Saver Plan NW Arkansas <input type="checkbox" id="3" name="table3" value="table3"
onchange="myFunction(event)"> </th>
</tr>
</thead>
<tr>
<td>$33.90</td>
</tr>
<tr>
<td>$161.30</td>
</tr>
<tr>
<td>$53.30</td>
</tr>
<tr>
<td>$186.20</td>
</tr>
<tr>
<td>HSA match:up to $350</td>
</tr>
<tr>
<td>HSA match:up to $700</td>
</tr>
<tr>
<td>$3000</td>
</tr>
<tr>
<td>$60</td>
</tr>
<tr>
<td>$660</td>
</tr>
<tr>
<td>$10</td>
</tr>
</table>
</div>
</div>
<div class="wrapper">
<button type="button" id="modalButton" class="btn btn-primary" data-toggle="modal" data-target="#myModal" onclick="javascript: return false;" >
Click me
</button>
</div>
</div>

I have a fixed table thead. If background-color: green, how to make th borders visible?

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
table, th, td {
border: 2px solid black;
padding: 0.5em 1em;
border-collapse: collapse;
}
.theadfixed {
position: sticky; top: 0;
color: black;
background-color: green;
}
.theadfixed tr {
border-color: black;
border: 2px solid black;
}
.theadfixed th{
text-align:center;
border: 2px solid black;
}
</style>
</head>
<body>
<table>
<thead class='theadfixed'>
<tr>
<th colspan="2" > Size </th>
</tr>
<tr>
<th> Length </th>
<th> Width </th>
</tr>
</thead>
<tbody>
<tr>
<td>654</td>
<td>1</td>
</tr>
<tr>
<td>256</td>
<td>2</td>
</tr>
<tr>
<td>78</td>
<td>3</td>
</tr>
<tr>
<td>654</td>
<td>4</td>
</tr>
<tr>
<td>654</td>
<td>5</td>
</tr>
<tr>
<td>256</td>
<td>6</td>
</tr>
<tr>
<td>78</td>
<td>7</td>
</tr>
<tr>
<td>654</td>
<td>8</td>
</tr>
<tr>
<td>654</td>
<td>9</td>
</tr>
<tr>
<td>256</td>
<td>10</td>
</tr>
<tr>
<td>78</td>
<td>11</td>
</tr>
<tr>
<td>654</td>
<td>12</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
<tr>
<td>654</td>
<td>17</td>
</tr>
<tr>
<td>256</td>
<td>18</td>
</tr>
<tr>
<td>78</td>
<td>19</td>
</tr>
<tr>
<td>654</td>
<td>20</td>
</tr>
<tr>
<td>654</td>
<td>21</td>
</tr>
<tr>
<td>256</td>
<td>22</td>
</tr>
<tr>
<td>78</td>
<td>23</td>
</tr>
<tr>
<td>654</td>
<td>24</td>
</tr>
<tr>
<td>654</td>
<td>25</td>
</tr>
<tr>
<td>256</td>
<td>26</td>
</tr>
<tr>
<td>78</td>
<td>27</td>
</tr>
<tr>
<td>654</td>
<td>28</td>
</tr>
<tr>
<td>654</td>
<td>29</td>
</tr>
<tr>
<td>256</td>
<td>30</td>
</tr>
<tr>
<td>78</td>
<td>31</td>
</tr>
<tr>
<td>654</td>
<td>32</td>
</tr>
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
table, th, td {
border: 2px solid black;
padding: 0.5em 1em;
border-collapse: collapse;
}
.theadfixed {
position: sticky; top: 0;
color: black;
background-color: green;
}
.theadfixed tr {
border-color: black;
border: 2px solid black;
}
.theadfixed th{
text-align:center;
border: 2px solid black;
}
</style>
</head>
<body>
<table>
<thead class='theadfixed'>
<tr>
<th colspan="2" > Size </th>
</tr>
<tr>
<th> Length </th>
<th> Width </th>
</tr>
</thead>
<tbody>
<tr>
<td>654</td>
<td>1</td>
</tr>
<tr>
<td>256</td>
<td>2</td>
</tr>
<tr>
<td>78</td>
<td>3</td>
</tr>
<tr>
<td>654</td>
<td>4</td>
</tr>
<tr>
<td>654</td>
<td>5</td>
</tr>
<tr>
<td>256</td>
<td>6</td>
</tr>
<tr>
<td>78</td>
<td>7</td>
</tr>
<tr>
<td>654</td>
<td>8</td>
</tr>
<tr>
<td>654</td>
<td>9</td>
</tr>
<tr>
<td>256</td>
<td>10</td>
</tr>
<tr>
<td>78</td>
<td>11</td>
</tr>
<tr>
<td>654</td>
<td>12</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
<tr>
<td>654</td>
<td>17</td>
</tr>
<tr>
<td>256</td>
<td>18</td>
</tr>
<tr>
<td>78</td>
<td>19</td>
</tr>
<tr>
<td>654</td>
<td>20</td>
</tr>
<tr>
<td>654</td>
<td>21</td>
</tr>
<tr>
<td>256</td>
<td>22</td>
</tr>
<tr>
<td>78</td>
<td>23</td>
</tr>
<tr>
<td>654</td>
<td>24</td>
</tr>
<tr>
<td>654</td>
<td>25</td>
</tr>
<tr>
<td>256</td>
<td>26</td>
</tr>
<tr>
<td>78</td>
<td>27</td>
</tr>
<tr>
<td>654</td>
<td>28</td>
</tr>
<tr>
<td>654</td>
<td>29</td>
</tr>
<tr>
<td>256</td>
<td>30</td>
</tr>
<tr>
<td>78</td>
<td>31</td>
</tr>
<tr>
<td>654</td>
<td>32</td>
</tr>
</tbody>
</table>
</body>
</html>
Above is the entire file.
I would like a vertical black line separating the "Length" and 'Width" column labels.
I think the background color covers up the border color.
I've tried different things such as:
border-color: black;
border: 2px solid black;
But nothing seems to work.
Can you help me make the th borders visible? Thanks
Try This :
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
table,
td,
th {
border-collapse: collapse;
padding: 0.5em 1em;
border: 2px solid black;
}
.theadfixed th {
text-align: center;
border: 2px solid black;
background-color: green;
position: sticky;
top: 0;
}
.theadfixed th::before {
content: '';
position: absolute;
height: 1px;
width: 100%;
top: -1px;
left: 0;
background-color: black;
}
.theadfixed th::after {
content: '';
position: absolute;
width: 100%;
bottom: 0;
left: 0;
background-color: black;
}
.SolveStickProblem{
top:35px!important;border:2px solid black;
}
</style>
</head>
<body>
<table>
<thead class='theadfixed'>
<tr>
<th colspan="2" > Size </th>
</tr>
<tr>
<th class="SolveStickProblem"> Length </th>
<th class="SolveStickProblem"> Width </th>
</tr>
</thead>
<tbody>
<tr>
<td>654</td>
<td>1</td>
</tr>
<tr>
<td>256</td>
<td>2</td>
</tr>
<tr>
<td>78</td>
<td>3</td>
</tr>
<tr>
<td>654</td>
<td>4</td>
</tr>
<tr>
<td>654</td>
<td>5</td>
</tr>
<tr>
<td>256</td>
<td>6</td>
</tr>
<tr>
<td>78</td>
<td>7</td>
</tr>
<tr>
<td>654</td>
<td>8</td>
</tr>
<tr>
<td>654</td>
<td>9</td>
</tr>
<tr>
<td>256</td>
<td>10</td>
</tr>
<tr>
<td>78</td>
<td>11</td>
</tr>
<tr>
<td>654</td>
<td>12</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
<tr>
<td>654</td>
<td>17</td>
</tr>
<tr>
<td>256</td>
<td>18</td>
</tr>
<tr>
<td>78</td>
<td>19</td>
</tr>
<tr>
<td>654</td>
<td>20</td>
</tr>
<tr>
<td>654</td>
<td>21</td>
</tr>
<tr>
<td>256</td>
<td>22</td>
</tr>
<tr>
<td>78</td>
<td>23</td>
</tr>
<tr>
<td>654</td>
<td>24</td>
</tr>
<tr>
<td>654</td>
<td>25</td>
</tr>
<tr>
<td>256</td>
<td>26</td>
</tr>
<tr>
<td>78</td>
<td>27</td>
</tr>
<tr>
<td>654</td>
<td>28</td>
</tr>
<tr>
<td>654</td>
<td>29</td>
</tr>
<tr>
<td>256</td>
<td>30</td>
</tr>
<tr>
<td>78</td>
<td>31</td>
</tr>
<tr>
<td>654</td>
<td>32</td>
</tr>
</tbody>
</table>
</body>
</html>
Also here is Docs of HTML Table
Specify border width....
Try this:
.theadfixed th {
text-align:center;
border: 2px solid black;
}
Edit:
Add this to your css:
tbody td:nth-child(odd) {
border-right: 4px solid black;
}
tbody td:nth-child(even) {
border-left: 4px solid black;
}
Final file:
please notice that I have used the snippets in stackoverflow, so you can run it right here and see the result. :)
table, th, td {
border: 2px solid black;
padding: 0.5em 1em;
border-collapse: collapse;
}
.theadfixed {
position: sticky; top: 0;
color: black;
background-color: green;
}
.theadfixed tr {
border-color: black;
border: 2px solid black;
}
.theadfixed th{
text-align:center;
border: 2px solid black;
}
tbody td:nth-child(odd) {
border-right: 4px solid black;
}
tbody td:nth-child(even) {
border-left: 4px solid black;
}
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<table>
<thead class='theadfixed'>
<tr>
<th> Length </th>
<th> Width </th>
</tr>
</thead>
<tbody>
<tr>
<td>654</td>
<td>1</td>
</tr>
<tr>
<td>256</td>
<td>2</td>
</tr>
<tr>
<td>78</td>
<td>3</td>
</tr>
<tr>
<td>654</td>
<td>4</td>
</tr>
<tr>
<td>654</td>
<td>5</td>
</tr>
<tr>
<td>256</td>
<td>6</td>
</tr>
<tr>
<td>78</td>
<td>7</td>
</tr>
<tr>
<td>654</td>
<td>8</td>
</tr>
<tr>
<td>654</td>
<td>9</td>
</tr>
<tr>
<td>256</td>
<td>10</td>
</tr>
<tr>
<td>78</td>
<td>11</td>
</tr>
<tr>
<td>654</td>
<td>12</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
</tbody>
</table>
</body>
</html>
Before going through the code you should know that position:sticky; does not work on <theads> neither <tr>.
So an effective and simple way would be to use postition:sticky; on the the <th> element.
Also, there is no point in setting border property multiple times to the same element as if it would magically fix your issue.
However on scrolling you see that the border around the <th> moves up. Hence to still mimic the border on the top and bottom, css psudeo elements have been added.
If you need further clarification i suggest you to check this post from css-tricks by chris coyier. https://css-tricks.com/position-sticky-and-table-headers/
<!DOCTYPE html>
<html>
<head>
<title>Tesst</title>
<style>
table {
border-collapse: collapse;
}
table,
td,
th {
padding: 0.5em 1em;
border: 2px solid black;
}
.theadfixed th {
position: sticky;
top: 0;
text-align: center;
border: 2px solid black;
background-color: green;
}
.theadfixed th::before {
content: '';
position: absolute;
height: 2px;
width: 100%;
top: -1px;
left: 0;
background-color: black;
}
.theadfixed th::after {
content: '';
position: absolute;
height: 1px;
width: 100%;
bottom: 0;
left: 0;
background-color: black;
}
</style>
</head>
<body>
<table>
<thead class='theadfixed'>
<tr>
<th> Length </th>
<th> Width </th>
</tr>
</thead>
<tbody>
<tr>
<td>654</td>
<td>1</td>
</tr>
<tr>
<td>256</td>
<td>2</td>
</tr>
<tr>
<td>78</td>
<td>3</td>
</tr>
<tr>
<td>654</td>
<td>4</td>
</tr>
<tr>
<td>654</td>
<td>5</td>
</tr>
<tr>
<td>256</td>
<td>6</td>
</tr>
<tr>
<td>78</td>
<td>7</td>
</tr>
<tr>
<td>654</td>
<td>8</td>
</tr>
<tr>
<td>654</td>
<td>9</td>
</tr>
<tr>
<td>256</td>
<td>10</td>
</tr>
<tr>
<td>78</td>
<td>11</td>
</tr>
<tr>
<td>654</td>
<td>12</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>13</td>
</tr>
<tr>
<td>256</td>
<td>14</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
<tr>
<td>654</td>
<td>16</td>
</tr>
<tr>
<td>78</td>
<td>15</td>
</tr>
</tbody>
</table>
</body>
</html>

How to retain the width of table columns when hiding columns?

I have a table that has six columns, five of which can be hidden based on user selection(s). The issue that I'm having is that when a column is hidden all other columns expand to fill the space that the hidden column occupied. What I would like to occur instead is for the column to just hide and the remaining columns shift to the left while retaining the widths that they were given. None of the answers that I have found on here seem to address this particular issue.
Below is snips of both my js and css along with screen grabs.
js:
<table className="hours table table-bordered table-sm" table-layout="fixed">
<thead>
<tr>
<th scope="col"
colSpan="3"
className="row-dow"
>
Hours
</th>
<th
scope="col"
colSpan="2"
align="center"
hidden={this.state.kitchenHoursSame}
className="row-16"
>
Kitchen Hours
</th>
<th
scope="col"
colSpan="2"
align="center"
hidden={!this.state.breakfast}
className="row-16"
>
Breakfast Special
</th>
...
</tr>
<tr>
<th
scope="col"
// className="row-8 "
>
Day
</th>
<th
scope="col"
className="row-8"
>
Open
</th>
<th
scope="col"
className="row-8"
>
Close
</th>
<th
scope="col"
hidden={this.state.kitchenHoursSame}
className="row-8"
>
Open
</th>
<th
scope="col"
hidden={this.state.kitchenHoursSame}
className="row-8"
>
Close
</th>
<th
scope="col"
hidden={!this.state.breakfast}
className="row-8"
>
1234567890123
</th>
<th
scope="col"
hidden={!this.state.breakfast}
className="row-8"
>
End
</th>
...
</tr>
</thead>
<tbody>
{this.state.DOW.map((dowList, i) =>
<tr>
<th scope="row" key={dowList.i}>{dowList.long}</th>
<td>
<select name="timeofday"
value={this.state.timeofday}
onChange={this.handleInputChange}>
<option>
(open)
</option>
</select>
</td>
...
</tr>
)}
</tbody>
</table>
css:
.hours {
table-layout: fixed;
/* width: 90%; */
width: 1500px;
white-space: nowrap;
}
.hours td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.row-dow {
width: 20px;
}
.row-16 {
width: 16px;
}
.row-8 {
width: 8px;
}
Any help would be appreciated even if it is being told that I shouldn't be using tables and should be using something else.
The snippet below shows you how different width defined tables behave when a column is going to be deleted.
window.addEventListener("load", () => {
const firstTDs = Array.from(
document.querySelectorAll("td:nth-child(3)")
).concat(Array.from(document.querySelectorAll("th:nth-child(3)")));
document.querySelector(".remove").addEventListener(
"click",
() => {
firstTDs.forEach(td => {
td.parentNode.removeChild(td);
});
},
{ once: true }
);
});
.full-width {
width: 100%;
}
.fixed-width {
width: 600px;
}
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<h5>Auto width</h5>
<table class="tbl mdl-data-table mdl-shadow--2dp">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Material</th>
<th>Unit price</th>
<th>Quantity</th>
<th>Unit price</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td>
<td>$2.90</td>
<td>25</td>
<td>$2.90</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Plywood (Birch)</td>
<td>$1.25</td>
<td>50</td>
<td>$1.25</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Laminate (Gold on Blue)</td>
<td>$2.35</td>
<td>10</td>
<td>$2.35</td>
</tr>
</tbody>
</table>
<h5>Full width</h5>
<table class="full-width mdl-data-table mdl-shadow--2dp">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Material</th>
<th>Unit price</th>
<th>Quantity</th>
<th>Unit price</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td>
<td>$2.90</td>
<td>25</td>
<td>$2.90</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Plywood (Birch)</td>
<td>$1.25</td>
<td>50</td>
<td>$1.25</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Laminate (Gold on Blue)</td>
<td>$2.35</td>
<td>10</td>
<td>$2.35</td>
</tr>
</tbody>
</table>
<h5>Fixed width</h5>
<table class="fixed-width mdl-data-table mdl-shadow--2dp">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Material</th>
<th>Unit price</th>
<th>Quantity</th>
<th>Unit price</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td>
<td>$2.90</td>
<td>25</td>
<td>$2.90</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Plywood (Birch)</td>
<td>$1.25</td>
<td>50</td>
<td>$1.25</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Laminate (Gold on Blue)</td>
<td>$2.35</td>
<td>10</td>
<td>$2.35</td>
</tr>
</tbody>
</table>
<h5>Actions</h5>
<button class="remove mdl-button mdl-button--raised">Remove Quantity</button>
If you have no problem rendering table content everytime, this can be handled using css property visibility: hidden; which hides the element with space occupied in the dom. See for : visibilty hidden
Approach :
Instead of using hidden attribute on th or td, i have used class = hideColumn which is defined to hide the element.
Next border: none to remove the border from the element.
In your case, you can also use 'class' attribute to achieve this.
If this is not helpful please let me know in the comments, or if anything can be done to take this near to required solution.
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
font-size: 10px;
}
.hideColumn {
visibility: hidden;
border: none;
}
h2 {
font-size: 12px;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
<h2>Visible All Column Table</h2>
<table>
<tr>
<th >Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr >
<td >Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
<br>
<h2>Hidden 1st Column Table</h2>
<table>
<tr>
<th class='hideColumn'>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr >
<td class='hideColumn'>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td class='hideColumn'>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
<br>
<h2>Hidden 2nd Column Table</h2>
<table>
<tr>
<th >Company</th>
<th class='hideColumn'>Contact</th>
<th>Country</th>
</tr>
<tr >
<td >Alfreds Futterkiste</td>
<td class='hideColumn'>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td >Centro comercial Moctezuma</td>
<td class='hideColumn'>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
Approach 2:
Just make the text transparent.
.otherDiv table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
font-size: 10px;
border: 1px solid #dddddd;
}
.otherDiv .hideColumn {
color: transparent;
}
h2 {
font-size: 12px;
}
.otherDiv td, th {
border-top: 1px solid #dddddd;
border-bottom: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
<div class='otherDiv'>
<h2>Visible All Column Table</h2>
<table>
<tr>
<th >Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr >
<td >Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
<br>
<h2>Hidden 1st Column Table</h2>
<table>
<tr>
<th class='hideColumn'>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr >
<td class='hideColumn'>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td class='hideColumn'>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
<br>
<h2>Hidden 2nd Column Table</h2>
<table>
<tr>
<th >Company</th>
<th class='hideColumn'>Contact</th>
<th>Country</th>
</tr>
<tr >
<td >Alfreds Futterkiste</td>
<td class='hideColumn'>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td >Centro comercial Moctezuma</td>
<td class='hideColumn'>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
</div>

How to structure bootrap tables in this way?

I'm looking to structure the tables in this way:
I tried doing that but I don't know how to put two columns inside a row (inch, cm)
It's a clothing store of a friend so I'd appreciate any help in this.
Did you try to do like this?
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
text-align:center;
}
.title{
background-color:red;
}
.sub-title{
background-color:lightgreen;
}
.footer{
background-color:lightcoral;
}
<table>
<thead>
<tr class="title">
<th colspan="7">Size Table</th>
</tr>
<tr class="sub-title">
<th rowspan="2"></th>
<th colspan="2">Bust</th>
<th colspan="2">Bust</th>
<th colspan="2">Bust</th>
</tr>
<tr class="sub-title">
<th>CH</th>
<th>CM</th>
<th>CH</th>
<th>CM</th>
<th>CH</th>
<th>CM</th>
</tr>
</thead>
<tbody>
<tr>
<td>S</td>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>Col4</td>
<td>Col5</td>
<td>Col6</td>
</tr>
<tr>
<td>M</td>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>Col4</td>
<td>Col5</td>
<td>Col6</td>
</tr>
<tr>
<td>L</td>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>Col4</td>
<td>Col5</td>
<td>Col6</td>
</tr>
</tbody>
<tfoot>
<tr class="footer">
<th colspan="7">description</th>
</tr>
</tfoot>
</table>
this code will help you. check the below jsfiddle link
https://jsfiddle.net/Gurmatpal/aq9Laaew/221894/
Check This Code. I think this will help you
table {
empty-cells: show;
border: 1px solid #000;
}
table td,
table th {
min-width: 2em;
min-height: 2em;
border: 1px solid #000;
}
<table>
<thead>
<tr>
<th rowspan="2"></th>
<th colspan="2"> </th>
<th colspan="2"> </th>
</tr>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>

Resources