Table not resizing columns as per % in colgroup - html

Can someone advise on why the columns aren't resizing according to their %s in colgroup?
PROBLEM: Make something like 50% first column 25% second column and third. While preserving display block on the tbody, such that we have scroll on the body not the whole table. SOLUTION: Leave in all the code like is below, but use td:nth-child property to manually set % width instead of using colgroup (because it required that display is not block but table-row-group).
I have tried using '3*','1*','1*' for the col width as well, to no avail. I think it must have to do something with the fact that I am placing the table inside a div container or due to display:block property, perhaps it has to be display: table. But when I do display: table, then table takes up only 50% of the container space and floats to left and columns are still of equal width. Thanks for any help!
EDIT: I have also tried style="width: 100%" on the table.
EDIT EDIT: removing display:block from .fixed_header thead tr and .fixed_header tbody fixes the issue for the header. Also, setting width:100% in .fixed_header th, .fixed_header td almost fixes it, it is a little bit misalligned.
.table-container {
position: absolute;
display: block;
height: 94%;
width: 100%;
margin-top: 10px;
padding: 10px;
top: 15px;
}
// https://codepen.io/GhostRider/pen/GHaFw
.style-2::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color: #F5F5F5;
}
.style-2::-webkit-scrollbar
{
width: 12px;
background-color: #F5F5F5;
}
.style-2::-webkit-scrollbar-thumb
{
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
background-color: #F4F7F7;
}
table, tbody {
width: 100%;
height: 100%;
position: relative;
display: inline-block;
table-layout: fixed;
}
.fixed_header{
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
.fixed_header tbody{
display:block;
width: 100%;
overflow-y: auto;
height: 90%;
}
.fixed_header thead tr {
display: block;
border-bottom: 1px solid black;
}
.fixed_header th, .fixed_header td {
padding: 5px;
text-align: left;
width: 200px;
}
<div class="table-container">
<table class="fixed_header">
<colgroup style="width: 100%;">
<col span="1" style="width: 50%;">
<col span="1" style="width: 25%;">
<col span="1" style="width: 25%;">
</colgroup>
<thead>
<tr>
<th>Factor</th>
<th>y_i</th>
<th>F_i</th>
</tr>
</thead>
<tbody class="style-2">
<tr>
<td>row 1-0</td>
<td>row 1-1</td>
<td>row 1-2</td>
</tr>
<tr>
<td>row 2-0</td>
<td>row 2-1</td>
<td>row 2-2</td>
</tr>
<tr>
<td>row 3-0</td>
<td>row 3-1</td>
<td>row 3-2</td>
</tr>
<tr>
<td>row 4-0</td>
<td>row 4-1</td>
<td>row 4-2</td>
</tr>
<tr>
<td>row 5-0</td>
<td>row 5-1</td>
<td>row 5-2</td>
</tr>
<tr>
<td>row 6-0</td>
<td>row 6-1</td>
<td>row 6-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
</tbody>
</table>
</div>

Removing the below classes solved the issue.
table, tbody {
width: 100%;
height: 100%;
position: relative;
display: inline-block;
table-layout: fixed;
}
.fixed_header tbody{
display:block;
width: 100%;
overflow-y: auto;
height: 90%;
}
.fixed_header thead tr {
display: block;
border-bottom: 1px solid black;
}
I see the default display table-row-group of the tbody has been replaced with display:inline-block . My guess is that these display properties seen below make elements behave like tables and their children and consequently apply table grouping rules on them. Fiddle here
display: table;
display: table-cell;
display: table-column;
display: table-colgroup;
display: table-header-group;
display: table-row-group;
display: table-footer-group;
display: table-row;
display: table-caption;

<table style="width: 100%">
<colgroup>
<col span="1" style="width: 50%;">
<col span="1" style="width: 25%;">
<col span="1" style="width: 25%;">
</colgroup>
<!-- Put <thead>, <tbody>, and <tr>'s here! -->
<tbody>
<tr>
<td style="background-color: #777">50%</td>
<td style="background-color: #aaa">25%</td>
<td style="background-color: #777">25%</td>
</tr>
<tr>
<td>row 1-0</td>
<td>row 1-1</td>
<td>row 1-2</td>
</tr>
<tr>
<td>row 2-0</td>
<td>row 2-1</td>
<td>row 2-2</td>
</tr>
<tr>
<td>row 3-0</td>
<td>row 3-1</td>
<td>row 3-2</td>
</tr>
<tr>
<td>row 4-0</td>
<td>row 4-1</td>
<td>row 4-2</td>
</tr>
<tr>
<td>row 5-0</td>
<td>row 5-1</td>
<td>row 5-2</td>
</tr>
<tr>
<td>row 6-0</td>
<td>row 6-1</td>
<td>row 6-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
</tbody>
Try this! I hope this help. Is working for me.

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div class="table-container">
<table class="fixed_header" style="width: 100%;">
<thead>
<tr>
<th style="width: 50%;">Factor</th>
<th style="width: 25%;">y_i</th>
<th style="width: 25%;">F_i Factor </th>
</tr>
</thead>
<tbody class="style-2">
<tr>
<td>row 1-0</td>
<td>row 1-1</td>
<td>row 1-2</td>
</tr>
<tr>
<td>row 2-0</td>
<td>row 2-1</td>
<td>row 2-2</td>
</tr>
<tr>
<td>row 3-0</td>
<td>row 3-1</td>
<td>row 3-2</td>
</tr>
<tr>
<td>row 4-0</td>
<td>row 4-1</td>
<td>row 4-2</td>
</tr>
<tr>
<td>row 5-0</td>
<td>row 5-1</td>
<td>row 5-2</td>
</tr>
<tr>
<td>row 6-0</td>
<td>row 6-1</td>
<td>row 6-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

Please add this CSS :
Is working for me
*{ text-align: left; }
table{ width: 100%; max-width: 600px; }

Related

HTML tables in flex layout are getting overlapped after converting to PDF

Trying to convert html file to pdf using weasyprint, but due to bug in weasyprint, I can't use flex layout as it is overlapping the two tables in the first row. Is there any other workaround to get two tables in the first row side by side without disturbing other elements like <p> and two tables after that?
Instead of using flexboxes, need to use other alternative to achieve same align as mentioned in sample code!
<html>
<head>
<style>
/* Custom CSS */
table {
border-collapse: collapse;
width: 45%;
}
th,
td {
border: 1px solid black;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
/* td:first-child {
background-color: grey;
} */
.first-column {
background-color: rgb(187, 185, 185);
}
.mainWrapper {
display: flex;
flex-direction: column;
}
.rowTable {
display: flex;
flex-direction: row;
}
/* End Custom CSS */
</style>
</head>
<body>
<div class="mainWrapper">
<div class="rowTable">
<table style="margin-right: 20px;">
<tr>
<td class="first-column">table 111 Header 1</td>
<td>Header 2</td>
</tr>
<tr>
<td class="first-column">Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td class="first-column">Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
<table>
<tr>
<td class="first-column">table 222 Header 1</td>
<td>Header 2</td>
</tr>
<tr>
<td class="first-column">Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td class="first-column">Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
</div>
<div>
<p> some paragraph </p>
<div>
<div>
<table style="margin-bottom:20px;">
<tr>
<th>table 333 Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
<table>
<tr>
<th>table 444 Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Actual output:( in pdf)
You could use display: inline-table; on the tables (without display:flex on their parent element). I can't check that in weasyprint, but you can try:
table {
border-collapse: collapse;
width: 45%;
}
.rowTable table {
display: inline-table;
}
:not(.rowTable) table {
margin: 0 auto;
}
th,
td {
border: 1px solid black;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
.first-column {
background-color: rgb(187, 185, 185);
}
<div class="mainWrapper">
<div class="rowTable">
<table style="margin-right: 20px;">
<tr>
<td class="first-column">table 111 Header 1</td>
<td>Header 2</td>
</tr>
<tr>
<td class="first-column">Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td class="first-column">Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
<table>
<tr>
<td class="first-column">table 222 Header 1</td>
<td>Header 2</td>
</tr>
<tr>
<td class="first-column">Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td class="first-column">Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
</div>
<div>
<p> some paragraph </p>
<div>
<div>
<table style="margin-bottom:20px;">
<tr>
<th>table 333 Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
<table>
<tr>
<th>table 444 Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
</div>
</div>

CSS Excel-like 'Freeze panes' where the top lines stay above the columns?

I'm trying to achieve the following effect: I have a large table, generated from a mysql query, and I want the top rows to stay on the page, while the body of the table scrolls vertically.
I've managed to get that working, BUT I also want the entire table to be horizontally scrollable, because part of it is off the right edge of the window.
I've been working on this for days, and I'd be grateful for some help.
Here's what I've come up with so far:
My table looks like this:
<div id="topLines">
<div id="controlLine">
<div id="testheader">
This text is fixed!
</div>
</div>
</div>
<div class="resetFloat"></div>
<div id="memberTable">
<div id="tableHeader">
<div class="columnTitle" style="width: 100px;">Title 1</div>
<div class="columnTitle" style="width: 100px;">Title 2</div>
<div class="columnTitle" style="width: 100px;">Title 3</div>
.
.
.
<div class="columnTitle" style="width: 100px;">Title n</div>
</div>
<div class="resetFloat"></div>
<div id="tableBody">
<div class="tableRow">
<div class="tableCell" style="width: 100px;">Cell 1-1</div>
<div class="tableCell" style="width: 100px;">Cell 1-2</div>
.
.
</div>
<div class="resetFloat"></div>
<div class="tableRow">
<div class="tableCell" style="width: 100px;">Cell 2-1</div>
.
.
</div>
<div class="resetFloat"></div>
<div class="tableRow">
<div class="tableCell" style="width: 100px;">Cell 3-1</div>
.
.
</div>
<div class="resetFloat"></div>
<div class="tableRow">
<div class="tableCell" style="width: 100px;">Cell 4-1</div>
.
.
</div>
<div class="resetFloat"></div>
.
.
</div>
</div>
Here's my CSS:
.resetFloat{
clear: both;
}
#topLines{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 50px;
overflow: hidden;
}
#controlLine{
float: left;
width: 5000px;
height: 50px;
}
#memberTable{
float: left;
position: fixed;
top: 50px;
width: 5000px;
overflow-x: scroll;
overflow-y: hidden;
}
#tableHeader{
position: fixed;
top: 60px;
float: left;
height: 45px;
width: 8000px;
border-bottom: solid 1px white;
}
.columnTitle{
float: left;
text-align: center;
border-right: solid 1px white;
height: 45px;
}
#tableBody{
position: fixed;
top: 120px; /*Set top value to HeightOfTopFrameDiv*/
left: 0;
bottom: 0;
overflow-y: scroll;
width: 5000px;
}
.tableRow{
float: left;
width 5000px;
}
.tableCell{
float: left;
height: 30px;
border-right: solid 1px white;
}
body{
margin:0}
/* table with a fixed head*/
.table-holder {
position:fixed;
top:40pt;
left:0;right:0;
bottom:0;
overflow-y: scroll;
}
.table-fixed-head {
position: relative;
width: 100%
}
.table-fixed-head th {
position: sticky;
top: 0;
background-color: #efefef;
text-align: left;
}
/* make top lines fixed */
#topLines{
height:40pt;
position:fixed;
left:0;
right:0;
background:#aaa;
z-index:20
}
<!--options-->
<div id="topLines">
<div id="controlLine">
<div id="testheader">
This text is fixed!
</div>
</div>
</div>
<!--table-->
<div class="table-holder">
<table class="table-fixed-head">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>row 1</td>
<td>row 1</td>
<td>row 1</td>
<td>row 1</td>
</tr>
<tr>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
</tr>
<tr>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
</tr>
<tr>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
</tr>
<tr>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
<td>row 2</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
<td>row 3</td>
</tr>
</tbody>
</table>
</div>

How to make a div that displays table-row-group vertically scrollable?

I am building a table using only divs with the help of the css table display property(ies). I need my table to be flexible so I cannot use <table>.
Everything works fine except for .table-body. I set the display property to table-row-group so it behaves like a <tbody> but I want it to be scrollable. I set its overflow property to auto and it still does not work.
For example, I have this table:
<div class="table">
<div class="table-header">
<div class="table-row">
<div class="table-cell">Header 1</div>
<div class="table-cell">Header 2</div>
<div class="table-cell">Header 3</div>
</div>
</div>
<div class="table-body">
<div class="table-row">
<div class="table-cell">cell 1</div>
<div class="table-cell">cell 2</div>
<div class="table-cell">cell 3</div>
</div>
</div>
</div>
And this is the css for .table-body. I added a display property of table-row-group so it behaves like a <tbody>. It still does not have a scroll even with overflow set to auto.
.table-body {
display: table-row-group; // makes it behave like <tbody>
height: 100%;
overflow: auto; // does nothing
}
We need the following steps in order to achieve vertical scrolling:
1. Setting <tbody> to display:block so that we can apply the height and overflow property.
2. Setting the <thead><tr> to display:block.
But, since you are already using display property to set to table-related display values, I am not sure how can we apply two display values to a div.
You can achieve what you need using a slightly different approach though, like:
.fixed_header{
width: 400px;
table-layout: fixed;
border-collapse: collapse;
}
.fixed_header tbody{
display:block;
width: 100%;
overflow: auto;
height: 100px;
}
.fixed_header thead tr {
display: block;
}
.fixed_header thead {
background: black;
color:#fff;
}
.fixed_header th, .fixed_header td {
padding: 5px;
text-align: left;
width: 200px;
}
<table class="fixed_header">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Col 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>row 1-0</td>
<td>row 1-1</td>
<td>row 1-2</td>
<td>row 1-3</td>
<td>row 1-4</td>
</tr>
<tr>
<td>row 2-0</td>
<td>row 2-1</td>
<td>row 2-2</td>
<td>row 2-3</td>
<td>row 2-4</td>
</tr>
<tr>
<td>row 3-0</td>
<td>row 3-1</td>
<td>row 3-2</td>
<td>row 3-3</td>
<td>row 3-4</td>
</tr>
<tr>
<td>row 4-0</td>
<td>row 4-1</td>
<td>row 4-2</td>
<td>row 4-3</td>
<td>row 4-4</td>
</tr>
<tr>
<td>row 5-0</td>
<td>row 5-1</td>
<td>row 5-2</td>
<td>row 5-3</td>
<td>row 5-4</td>
</tr>
<tr>
<td>row 6-0</td>
<td>row 6-1</td>
<td>row 6-2</td>
<td>row 6-3</td>
<td>row 6-4</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
<td>row 7-3</td>
<td>row 7-4</td>
</tr>
</tbody>
</table>
Hope this helps.

Fixed header in HTML Table

I've tried every possible solution to get this to work, but nothing seems to be working.
I have this webpage I've created, and I have a table shown here, and I want to have my header fixed. That part I have mastered, but the thead columns dont align to the tbody columns.
I have tried assigning width to my td's manually, that didn't work either.
This is my code so far:
.tableSqlContent {
table-layout: fixed;
border-collapse: collapse;
}
.tableSqlContent th, td {
padding: 7px;
text-align: left;
}
.tableSqlContent thead {
background-color: #003265;
color: white;
font-weight: bold;
cursor: default;
}
.tableSqlContent thead tr {
display:inline-block;
position: relative;
height: 37px;
}
.tableSqlContent tbody tr td:nth-child(1) {min-width: 33%;}
.tableSqlContent tbody tr td:nth-child(2) {min-width: 20%;}
.tableSqlContent tbody tr td:nth-child(3) {min-width: 20%;}
.tableSqlContent tbody tr td:nth-child(4) {min-width: 10%;}
.tableSqlContent tbody tr td:nth-child(5) {min-width: 10%;}
.tableSqlContent tbody tr td:nth-child(6) {min-width: 7%;}
.tableSqlContent thead tr th:nth-child(1) {min-width: 33%;}
.tableSqlContent thead tr th:nth-child(2) {min-width: 20%;}
.tableSqlContent thead tr th:nth-child(3) {min-width: 20%;}
.tableSqlContent thead tr th:nth-child(4) {min-width: 10%;}
.tableSqlContent thead tr th:nth-child(5) {min-width: 10%;}
.tableSqlContent thead tr th:nth-child(6) {min-width: 7%;}
.tableSqlContent tbody {
display: block;
height: 700px;
overflow: auto;
}
.tableSqlContent tbody tr:nth-child(even) {
background-color: #eeeeee;
}
.tableSqlContent tbody tr:hover {
color: #003265;
cursor: pointer;
background-color: #dddddd;
}
<table Class="tableSqlContent">
<thead>
<tr>
<th>Connectionstring</th>
<th>Klinik Navn</th>
<th>IP_Adresse</th>
<th>P-nummer</th>
<th>Systemtype</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<?php
foreach($dbh->query($query) as $rows){
?>
<tr>
<td><?php echo $rows['ConnectionString']?></td>
<td><?php echo $rows['Name']?></td>
<td><?php echo $rows['IP_Adresse']?></td>
<td><?php echo $rows['Ydernummer']?></td>
<td><?php echo $rows['Systemtype']?></td>
<td><?php echo $rows['Version']?></td>
</tr>
<?php
}
?>
</tbody>
</table>
This is how it looks:
This seems to be working.
.fixed_header {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
.fixed_header tbody {
display: block;
overflow: auto;
height: 200px;
width: 100%;
}
.fixed_header thead {
background: black;
color: #fff;
}
.fixed_header thead tr {
display: block;
}
.fixed_header th,
.fixed_header td {
text-align: left;
width: 100px;
max-width: 100px;
}
<table class="fixed_header">
<thead>
<tr>
<th>Connection string</th>
<th>Klinik Navn</th>
<th>IP_Adresse</th>
<th>P-nummer</th>
<th>Systemtype</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>row 1-0</td>
<td>row 1-1</td>
<td>row 1-2</td>
<td>row 1-3</td>
<td>row 1-4</td>
</tr>
<tr>
<td>row 2-0</td>
<td>row 2-1</td>
<td>row 2-2</td>
<td>row 2-3</td>
<td>row 2-4</td>
</tr>
<tr>
<td>row 3-0</td>
<td>row 3-1</td>
<td>row 3-2</td>
<td>row 3-3</td>
<td>row 3-4</td>
</tr>
<tr>
<td>row 4-0</td>
<td>row 4-1</td>
<td>row 4-2</td>
<td>row 4-3</td>
<td>row 4-4</td>
</tr>
<tr>
<td>row 5-0</td>
<td>row 5-1</td>
<td>row 5-2</td>
<td>row 5-3</td>
<td>row 5-4</td>
</tr>
<tr>
<td>row 6-0</td>
<td>row 6-1</td>
<td>row 6-2</td>
<td>row 6-3</td>
<td>row 6-4</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
<td>row 7-3</td>
<td>row 7-4</td>
</tr>
<tr>
<td>row 8-0</td>
<td>row 8-1</td>
<td>row 8-2</td>
<td>row 8-3</td>
<td>row 8-4</td>
</tr>
<tr>
<td>row 9-0</td>
<td>row 9-1</td>
<td>row 9-2</td>
<td>row 9-3</td>
<td>row 9-4</td>
</tr>
<tr>
<td>row 10-0</td>
<td>row 10-1</td>
<td>row 10-2</td>
<td>row 10-3</td>
<td>row 10-4</td>
</tr>
<tr>
<td>row 11-0</td>
<td>row 11-1</td>
<td>row 11-2</td>
<td>row 11-3</td>
<td>row 11-4</td>
</tr>
<tr>
<td>row 12-0</td>
<td>row 12-1</td>
<td>row 12-2</td>
<td>row 12-3</td>
<td>row 12-4</td>
</tr>
<tr>
<td>row 13-0</td>
<td>row 13-1</td>
<td>row 13-2</td>
<td>row 13-3</td>
<td>row 13-4</td>
</tr>
<tr>
<td>row 14-0</td>
<td>row 14-1</td>
<td>row 14-2</td>
<td>row 14-3</td>
<td>row 14-4</td>
</tr>
<tr>
<td>row 15-0</td>
<td>row 15-1</td>
<td>row 15-2</td>
<td>row 15-3</td>
<td>row 15-4</td>
</tr>
<tr>
<td>row 16-0</td>
<td>row 16-1</td>
<td>row 16-2</td>
<td>row 16-3</td>
<td>row 16-4</td>
</tr>
<tr>
<td>row 17-0</td>
<td>row 17-1</td>
<td>row 17-2</td>
<td>row 17-3</td>
<td>row 17-4</td>
</tr>
<tr>
<td>row 18-0</td>
<td>row 18-1</td>
<td>row 18-2</td>
<td>row 18-3</td>
<td>row 18-4</td>
</tr>
<tr>
<td>row 19-0</td>
<td>row 19-1</td>
<td>row 19-2</td>
<td>row 19-3</td>
<td>row 19-4</td>
</tr>
<tr>
<td>row 20-0</td>
<td>row 20-1</td>
<td>row 20-2</td>
<td>row 20-3</td>
<td>row 20-4</td>
</tr>
<tr>
<td>row 21-0</td>
<td>row 21-1</td>
<td>row 21-2</td>
<td>row 21-3</td>
<td>row 21-4</td>
</tr>
</tbody>
</table>
You need to remove some css because is in conflict:
.tableSqlContent {
table-layout: fixed;
border-collapse: collapse;
overflow: auto;
}
.tableSqlContent th, td {
padding: 7px;
text-align: left;
}
.tableSqlContent thead {
background-color: #003265;
color: white;
font-weight: bold;
cursor: default;
}
.tableSqlContent tbody tr:nth-child(even) {
background-color: #eeeeee;
}
.tableSqlContent tbody tr:hover {
color: #003265;
cursor: pointer;
background-color: #dddddd;
}
thead th {
position: sticky;
position: -webkit-sticky;
top: 0px;
z-index: 999999;
background-color: #003265;
}
<table class="tableSqlContent">
<thead>
<tr>
<th>Connectionstring</th>
<th>Klinik Navn</th>
<th>IP_Adresse</th>
<th>P-nummer</th>
<th>Systemtype</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
<td>4444</td>
<td>5555</td>
<td>6666</td>
</tr>
</tbody>
</table>
hope it helps
-- added css for sticky header.

Vertical bar for each tbody inside a table

I've a dynamic HTML page which has a table with multiple 'tbody' elements.
Now, I'm stuck with CSS as I need to show a vertical bar inside each of the 'tbody' as shown in the image attached.
How could I get this done? I tried using 'tr::after' and creating a bar, but didn't help.
Here's my html:
Could you please help me achieve this?
<table>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
</table>
In addition to #connor
This does the trick:
tbody {
margin: 10px;
display: block;
}
<style>
table {
border-collapse: collapse;
}
td:first-child {
border-right: 1px solid #000;
}
tbody {
margin: 10px;
display: block;
}
</style>
<table>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
</table>
Try giving the :first-child td a border-right. If you're gonna have multiple columns, in stead of 2, try using :not(:last-child) in stead of :first-child.
<style>
table {
border-collapse: collapse;
}
td:first-child {
border-right: 1px solid #000;
}
</style>
<table>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
<tbody class="container">
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</tbody>
</table>