How to show second table when other is hidden by JS - javascript

I have a searchable table using HTML, CSS and JavaScript - the JavaScript hides the contents of the table, except for the headers and then populates when details are entered into the search bar e.g. 1001, 1002, 1003. However, I'm also now wanting to add a simple separate table on the same page, but the JavaScript seems to hide this table completely as well.
Is there something I can add to the JavaScript to bypass the second table or are there other ways to do this? I'm a complete novice at this, so apologies if things aren't on point as I've had to research a lot of the JavaScript to fit what I was after.
First table
window.onload = function() {
var rows = document.querySelectorAll('tr:not(.active-row)');
for (var i = 0; i < rows.length; i++) {
rows[i].style.display = 'none';
}
}
function ContactsearchFX() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("compliance-table");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = 'none';
}
}
}
var rows = document.querySelectorAll('tr:not(.active-row)');
if (input.value.length == 0) {
for (var i = 0; i < rows.length; i++) {
rows[i].style.display = 'none';
}
}
}
var allTableCells = document.getElementsByTagName("td");
for(var i = 0, max = allTableCells.length; i < max; i++) {
var node = allTableCells[i];
var currentText = node.childNodes[0].nodeValue;
}
#myInput {
width: 25%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: thin solid #ddd;
margin-bottom: 12px;
}
#compliance-table {
border-collapse: collapse;
margin: 25px 0;
font-size: 0.6em;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
#compliance-table th,
#compliance-table td {
padding: 12px 15px;
border-left: thin solid #dddddd;
border-right: thin solid #dddddd;
text-align: center;
}
#compliance-table tbody tr {
border-bottom: thin solid #dddddd;
}
#compliance-table tbody tr.active-row {
font-weight: bold;
color: #0087AE;
}
<input type="text" id="myInput" onkeyup="ContactsearchFX()" placeholder="Search...">
<table id="compliance-table">
<thead>
<tr class="active-row">
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">Details</th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">Total No</th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">w/e 10th Sep</th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">w/e 17th Sep</th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">w/e 1st Oct </th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">w/e 22nd Oct </th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">w/e 5th Nov</th>
<th colspan="3" style="background-color: #0087AE; color: white; text-align: center; vertical-align: middle;">w/e 19th Nov</th>
</tr>
</thead>
<tbody>
<tr class="active-row">
<th style="text-align: center; vertical-align: middle;">Test 1</th>
<th style="text-align: center; vertical-align: middle;">Test 2</th>
<th style="text-align: center; vertical-align: middle;">Test 3</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
<th style="text-align: center; vertical-align: middle;">QIVe</th>
<th style="text-align: center; vertical-align: middle;">QIVc</th>
<th style="text-align: center; vertical-align: middle;">aQIV</th>
</tr>
<tr>
<td>2</td>
<td>1001</td>
<td>Test 1001</td>
<td>46</td>
<td>60</td>
<td>83</td>
<td>12</td>
<td>35</td>
<td>42</td>
<td>5</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>22</td>
<td>42</td>
<td>0</td>
<td>4</td>
<td>0</td>
<td>23</td>
<td>0</td>
<td>0</td>
<td>7</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>1002</td>
<td>Test 1002</td>
<td>46</td>
<td>60</td>
<td>83</td>
<td>12</td>
<td>35</td>
<td>42</td>
<td>5</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>22</td>
<td>42</td>
<td>0</td>
<td>4</td>
<td>0</td>
<td>23</td>
<td>0</td>
<td>0</td>
<td>7</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>1003</td>
<td>Test 1003</td>
<td>31</td>
<td>20</td>
<td>31</td>
<td>8</td>
<td>12</td>
<td>16</td>
<td>3</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>7</td>
<td>16</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>15</td>
<td>0</td>
<td>0</td>
<td>5</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>
Second table
<!DOCTYPE html>
<html>
<head>
<style>
#flu-table {
border-collapse: collapse;
width: 70%;
position: fixed;
}
#flu-table td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
</head>
<body>
<h2>Key</h2>
<table id="flu-table">
<tr>
<th>Type</th>
<th>Applicable to</th>
</tr>
<tr>
<td>QIVe</td>
<td>Under 65 ONLY</td>
</tr>
<tr>
<td>QIVc</td>
<td>Under 65 - <em>can be used for over 65 if aQIV is not available</em></td>
</tr>
<tr>
<td>aQIV</td>
<td>Over 65 ONLY</td>
</tr>
</table>
</body>
</html>

Related

th and td not getting same width

I am not able to match the width of td and th and get a gap between the table and the scrollbar.
.table_fixed tbody {
display: block;
height: 500px;
overflow-y: scroll;
}
.table_fixed thead {
display: block;
}
Please see the below jsfiddle to see the entire code:
https://jsfiddle.net/w80bz1vc/
There was some unnecessary css which I've removed,
These two rules specifically,
.table_fixed tbody {
display: block;
height: 500px;
overflow-y: scroll;
}
.table_fixed thead {
display: block;
float: inline-end;
}
As a rule of thumb, try not to change the display property of the default table elements as much as possible.
body {
background-image: url("https://img.collegedekhocdn.com/media/img/institute/crawled_images/10450_gogte_new.jpg?tr=w-250,h-150");
background-repeat: round;
background-attachment: fixed;
background-size: cover;
}
#logo {
position: fixed;
top: 0;
left: 0;
}
table {
font-family: arial, sans-serif;
width: 70%;
margin: 0 auto;
border: 1px solid;
}
td,
th {
border: 1px solid black;
text-align: center;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f3e5f5;
}
tr:nth-child(odd) {
background-color: #fff;
}
h2 {
text-align: center;
font-family: "Times New Roman", Times, serif;
margin: 1rem;
}
.pink-bg {
background-color: #f3e5f5;
}
#admin-login-id {
justify-content: flex;
position: absolute;
right: 45%;
align-content: center;
}
.loader {
position: absolute;
bottom: 50%;
right: 50%;
}
.admin_button {
text-align: center;
}
.add_button {
text-align: center;
display: none;
}
.title_class {
display: none;
}
.add2_button {
display: none;
text-align: center;
}
.disable-delete {
cursor: pointer;
color: gray;
}
.active-delete {
cursor: pointer;
/* add external cursor */
color: Black;
background-color: red;
}
<table class="tab_id table_fixed" style="">
<!--Spinner -->
<thead>
<tr class="th purple lighten-2">
<th class="sem_count" colspan="2">BCA I Sem</th>
<th class="sem_count" colspan="2">BCA II Sem</th>
<th class="sem_count" colspan="2">BCA III Sem</th>
<th class="remove_col"></th>
</tr>
<tr class="purple lighten-4">
<th>Subject</th>
<th>Professor</th>
<th>Subject</th>
<th>Professor</th>
<th>Subject</th>
<th>Professor</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<tr>
<td class="Mathematics_class">Mathematics</td>
<td>Sharma Sir</td>
<td class="Mathematics_class">Mathematics</td>
<td>Sharma Sir</td>
<td class="Mathematics_class">Mathematics</td>
<td>Sharma Sir</td>
<td><i onclick="deleteSubject('Mathematics')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="English_class">English</td>
<td>Gouri Mam</td>
<td class="English_class">English</td>
<td>Gouri Mam</td>
<td class="English_class">English</td>
<td>Gouri Mam</td>
<td><i onclick="deleteSubject('English')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Sanskrit_class">Sanskrit</td>
<td>Virat Sir</td>
<td class="Sanskrit_class">Sanskrit</td>
<td>Virat Sir</td>
<td class="Sanskrit_class">Sanskrit</td>
<td>Virat Sir</td>
<td><i onclick="deleteSubject('Sanskrit')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Science_class">Science</td>
<td>Shivani Mam</td>
<td class="Science_class">Science</td>
<td>Shivani Mam</td>
<td class="Science_class">Science</td>
<td>Shivani Mam</td>
<td><i onclick="deleteSubject('Science')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Electronics_class">Electronics</td>
<td>Shishir Sir</td>
<td class="Electronics_class">Electronics</td>
<td>Shishir Sir</td>
<td class="Electronics_class">Electronics</td>
<td>Shishir Sir</td>
<td><i onclick="deleteSubject('Electronics')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Testing_class">Testing</td>
<td>Vaishali Mam</td>
<td class="Testing_class">Testing</td>
<td>Vaishali Mam</td>
<td class="Testing_class">Testing</td>
<td>Vaishali Mam</td>
<td><i onclick="deleteSubject('Testing')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Chemestry_class">Chemestry</td>
<td>Subbu Sir</td>
<td class="Chemestry_class">Chemestry</td>
<td>Subbu Sir</td>
<td class="Chemestry_class">Chemestry</td>
<td>Subbu Sir</td>
<td><i onclick="deleteSubject('Chemestry')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Hindi_class">Hindi</td>
<td>Jadu sir</td>
<td class="Hindi_class">Hindi</td>
<td>Jadu sir</td>
<td class="Hindi_class">Hindi</td>
<td>Jadu sir</td>
<td><i onclick="deleteSubject('Hindi')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="A_class">A</td>
<td>ASD</td>
<td class="A_class">A</td>
<td>ASD</td>
<td class="A_class">A</td>
<td>ASD</td>
<td><i onclick="deleteSubject('A')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="R_class">R</td>
<td>FGH</td>
<td class="R_class">R</td>
<td>FGH</td>
<td class="R_class">R</td>
<td>FGH</td>
<td><i onclick="deleteSubject('R')" class="material-icons active-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
<tr>
<td class="Physics_class">Physics</td>
<td>Ramesh</td>
<td class="Physics_class">Physics</td>
<td>Ramesh</td>
<td class="Physics_class">Physics</td>
<td>Ramesh</td>
<td><i onclick="deleteSubject('Physics')" class="material-icons disable-delete" style="background-color: red; color: black;">delete</i></td>
</tr>
</tbody>
</table>

Scrollable table with fixed column fixed with equal size

I have a table with first column fixed so when the next column is scrolled first column item will always display, Now the problem is first column width have fixed value and the same is applying on the margin left, How can we make fluid width instead of fixed width so it resizes based on the column?
.table-main {
border: none;
border-right: solid 1px rgb(75, 90, 102);
border-collapse: separate;
border-spacing: 0;
font: normal 13px Arial, sans-serif;
}
.table-main thead th {
background-color: rgb(203, 220, 233);
border: none;
color: #336B6B;
padding: 10px;
text-align: left;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table-main tbody td {
border-bottom: solid 1px rgb(75, 90, 102);
color: #333;
padding: 10px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table {
position: relative;
}
.table-scroll {
margin-left: 131px; /*HOW TO HAVE THIS in Eqaul SIZE??*/
overflow-x: scroll;
overflow-y: visible;
padding-bottom: 5px;
width: 500px;
}
.table-main .fix-col {
border-left: solid 1px rgb(75, 90, 102);
border-right: solid 1px rgb(75, 90, 102);
left: 0;
position: absolute;
top: auto;
width: 110px; /*HOW TO HAVE THIS in Eqaul SIZE??*/
}
<div class="table">
<div class="table-scroll">
<table class="table-main">
<thead>
<tr>
<th class="fix-col">Name</th>
<th>Designation</th>
<th>Experience</th>
<th>Technology</th>
<th>Company</th>
<th>Location</th>
<th>Contact No.</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
</tbody>
</table>
</div>
</div>
What about using javascript to calculate and set the width of the fixed column(.fix-col) and the margin-left of the container div(.table-scroll)?
var columns = document.querySelectorAll('.fix-col');
var maxWidth = 0;
/* Loop through columns to get the widest one */
for (var i = 0; i < columns.length; i++) {
/* Get only the width, without any paddings */
var w = parseFloat(window.getComputedStyle(columns[i]).getPropertyValue('width'));
if (w > maxWidth) {
maxWidth = w;
}
}
/* Second loop to set the width */
for (var i = 0; i < columns.length; i++) {
columns[i].style.width = maxWidth + 'px';
}
/* And finally update the margin of the wrapping div */
var paddingPlusBorder = 21;
document.querySelector('.table-scroll').style.marginLeft = maxWidth + paddingPlusBorder + 'px';
.table-main {
border: none;
border-right: solid 1px rgb(75, 90, 102);
border-collapse: separate;
border-spacing: 0;
font: normal 13px Arial, sans-serif;
}
.table-main thead th {
background-color: rgb(203, 220, 233);
border: none;
color: #336B6B;
padding: 10px;
text-align: left;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table-main tbody td {
border-bottom: solid 1px rgb(75, 90, 102);
color: #333;
padding: 10px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table {
position: relative;
}
.table-scroll {
overflow-x: scroll;
overflow-y: visible;
padding-bottom: 5px;
width: 500px;
}
.table-main .fix-col {
border-left: solid 1px rgb(75, 90, 102);
border-right: solid 1px rgb(75, 90, 102);
left: 0;
position: absolute;
top: auto;
}
<div class="table">
<div class="table-scroll">
<table class="table-main" id="my-table">
<thead>
<tr>
<th class="fix-col">Name</th>
<th>Designation</th>
<th>Experience</th>
<th>Technology</th>
<th>Company</th>
<th>Location</th>
<th>Contact No.</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td class="fix-col">Some very long name</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">LooooooooooongNameeee</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
</tbody>
</table>
</div>
</div>
And if you want to support older IE versions you can use a custom function to get the column widths instead of using window.getComputedStyle(columns[i]).getPropertyValue('width').
function getWidth(element) {
if (getComputedStyle in window) {
return window.getComputedStyle(element).getPropertyValue('width');
}
if (currentStyle in element) {
return element.currentStyle.width;
}
var defaultWidthIfNoSupport = '100px';
return defaultWidthIfNoSupport;
}
You could use position: sticky Sticky Element in order to anchor to left the fixed column:
.fix-col {
position: sticky;
position: -webkit-sticky;
background-color: white; // <-- By default it's transparent
}
<table>
<tr>
<th class="fix-col">Name</th>
see the code applied to your snippet:
.table-main {
border: none;
border-right: solid 1px rgb(75, 90, 102);
border-collapse: separate;
border-spacing: 0;
font: normal 13px Arial, sans-serif;
}
.table-main thead th {
background-color: rgb(203, 220, 233);
border: none;
color: #336B6B;
padding: 10px;
text-align: left;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table-main tbody td {
border-bottom: solid 1px rgb(75, 90, 102);
color: #333;
padding: 10px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table-scroll {
overflow-x: scroll;
width: 500px;
}
.fix-col {
position: sticky;
position: -webkit-sticky;
background-color: white;
left: 0;
margin-left: 1em;
}
<div class="table">
<div class="table-scroll">
<table class="table-main">
<thead>
<tr>
<th class="fix-col">Name</th>
<th>Designation</th>
<th>Experience</th>
<th>Technology</th>
<th>Company</th>
<th>Location</th>
<th>Contact No.</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td class="fix-col">Bob</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">John</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Alessandro</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Joseph</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
<tr>
<td class="fix-col">Mark</td>
<td>Front End Developer</td>
<td>5 yrs</td>
<td>HTML,CSS</td>
<td>Google</td>
<td>California</td>
<td>9876543210</td>
<td>Google Office</td>
</tr>
</tbody>
</table>
</div>
</div>

HTML: Screen stutters during scrolling when crossing sticky text thats fixed at top of page

I tried searching stack overflow thinking that surely someone would have asked this noob question already. I couldn't find the solution to this hence posting as new question.
I have a HTML code that I need to show as a report.
<html>
<style>
body {
background-color: rgb(59, 75, 84);
font-family: arial, verdana, trebuchet, officina, sans-serif;
margin: 1; }
.top-container {
background-color: #f1f1f1;
padding: 1px;
text-align: center;
}
.mid-container {
background-color: rgb(38, 52 ,63);
padding: 1px;
text-align: left;
}
.header {
text-align: center;
padding: 5px 8px;
background: rgb(25, 165, 88);
color: #f1f1f1;
position:relative;
margin: 1;
z-index: 100;
}
.mid-container {
padding: 1px;
}
.sticky {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
.sticky + .mid-container {
position:absolute;
overflow: auto;
padding-top:auto;
}
table
{
margin-bottom: 10px;
vertical-align: top;
border: 0;
border-spacing: 1px;
padding: 2px;
}
.HeadingTable
{
width: 100%;
text-align: center;
margin-top: 15px;
margin-bottom: 30px;
margin-left: auto;
margin-right: auto;
background-color: rgb(220, 221, 222);
}
.SubHeadingTable
{
width: 100%;
text-align: center;
margin-top: 15px;
margin-bottom: 25px;
background-color: rgb(220, 221, 222);
}
.ResultTable
{
width: 100%;
text-align: left;
padding-right: 20px;
}
table.ResultTable td
{
vertical-align: top;
}
.OverallResultTable
{
width: 50%;
text-align: center;
margin-bottom: 20px;
margin-left: auto;
margin-right: auto;
font-weight: bold;
}
.TableHeadingCell
{
background-color: rgb(179, 179, 179);
font-family: arial, verdana, trebuchet, officina, sans-serif;
font-weight: bold;
text-align: center;
}
.CellNoColor
{
text-align: left;
vertical-align: top;
}
.DefaultCell
{
background-color: rgb(229, 229, 229);
text-align: left;
}
.NumberCell
{
background-color: rgb(229, 229, 229);
text-align: center;
min-width: 50px;
}
.PositiveResultCell
{
text-align: center;
background-color: rgb(25, 165, 88);
}
.NegativeResultCell
{
text-align: center;
background-color: rgb(240, 0, 0);
}
.WarningCell
{
text-align: center;
background-color: rgb(255, 255, 0);
}
.NegativeResult
{
background-color: rgb(240, 0, 0);
text-align: center;
font-weight: bold;
}
.PositiveResult
{
background-color: rgb(25, 165, 88);
text-align: center;
font-weight: bold;
}
.Heading1
{
font-family: arial, sans-serif;
font-weight: bold;
font-size: 26px;
}
.Heading2
{
font-family: arial, sans-serif;
font-weight: bold;
font-size: 20px;
}
.Heading3
{
font-family: arial, sans-serif;
font-weight: bold;
font-size: 18px;
margin-bottom: 20px;
margin-top: 20px;
}
.Heading4
{
font-family: arial, sans-serif;
font-weight: bold;
font-size: 16px;
margin-top: 10px;
margin-bottom: 10px;
}
.Heading5
{
font-family: arial, sans-serif;
font-weight: bold;
font-size: 14px;
margin-top: 8px;
margin-bottom: 8px;
}
p
{
Margin-bottom: 20px;
}
.TestGroupHeadingBackground
{
background-color: rgb(179, 179, 179);
}
.Indentation
{
margin-left: 20px;
}
</style>
<head>
<title>NVM Comparision Report</title>
</head>
<body>
<div class="top-container">
<h1>NVM Memory Comparision Report</h1>
</div>
<div class="header" id="myHeader">
<h2>Overall Report Passed</h2>
</div>
<div class="mid-container">
<h3>General Information</h3>
</div>
<div class="Heading4">Test Setup</div>
<div class="Indentation">
<table cellpadding="10">
<td class="CellNoColor">Report Generation: </td>
<td class="CellNoColor">Success</td>
</tr>
<tr>
<td class="CellNoColor">File's Root Path: </td>
<td class="CellNoColor">New XXX Path: XXX</td>
</tr>
<tr>
<td class="CellNoColor">Configuration Comment: </td>
<td class="CellNoColor">XXX</td>
</tr>
<tr>
<td class="CellNoColor">XXX: </td>
<td class="CellNoColor">XXX</td>
</tr>
</table>
</div>
<div class="Heading4">Blocks Present in DataConfig</div>
<div class="Heading5">New Version:0042</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width = "70%">
<tr>
<th class="TableHeadingCell" width="18%">Dataset Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;>SparePart Number</th>
<th class="TableHeadingCell">Blocks Present</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Datasets</td>
<td class="DefaultCell" style = text-align:center;>All Sparepart Numbers</td>
<td class="DefaultCell"> Blocks 81, 99, 115, 120, 121, 133</td>
<td class="PositiveResult">Pass</td>
</tr>
</table>
</div>
<div class="Heading5">Old Version:0041</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width = "70%">
<tr>
<th class="TableHeadingCell" width="18%">Dataset Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;>SparePart Number</th>
<th class="TableHeadingCell">Blocks Present</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Datasets</td>
<td class="DefaultCell" style = text-align:center;>All Sparepart Numbers</td>
<td class="DefaultCell"> Blocks 81, 99, 115</td>
<td class="PositiveResult">Pass</td>
</tr>
</table>
</div>
<div class="Heading4">Following Blocks are Missing in New FEE Dumps:</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width = "70%">
<tr>
<th class="TableHeadingCell" width="18%">File Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;>SparePart Number</th>
<th class="TableHeadingCell">Blocks Missing</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Files</td>
<td class="DefaultCell" style = text-align:center;>All</td>
<td class="DefaultCell"></td>
<td class="WarningCell" rowspan=2>Pass</td>
</tr>
</table>
</div>
<div class="Heading4">Following Blocks are Missing in Old FEE Dumps:</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width = "70%">
<tr>
<th class="TableHeadingCell" width="18%">File Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;>SparePart Number</th>
<th class="TableHeadingCell">Blocks Missing</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Files</td>
<td class="DefaultCell" style = text-align:center;>All</td>
<td class="DefaultCell"></td>
<td class="WarningCell" rowspan=2>Pass</td>
</tr>
</table>
</div>
<table cellpadding="5" class="SubHeadingTable">
<tr>
<td>
<big class="Heading2">Detailed Comparision Between FEE DUMPs</big>
</td>
</tr>
</table>
<div class="Indentation"></div>
<table cellpadding="5" class="TestGroupHeadingBackground">
<tr>
<td>
<big class="Heading3">XXX : </big>
</td>
</tr>
</table>
<div class="Indentation">
<p>Report is based on data obtained from comparing files XXX and XXX in folder RdW.</p>
</div>
<div class="Indentation"></div>
<div class="Indentation">
<table cellpadding="5" class="ResultTable">
<tr>
<th class="TableHeadingCell" width="4%">Block ID</th>
<th class="TableHeadingCell" width="4%">Block Address</th>
<th class="TableHeadingCell" width="10%">Block Name</th>
<th class="TableHeadingCell" width="10%">Parameter Name</th>
<th class="TableHeadingCell" width="4%">Size</th>
<th class="TableHeadingCell" width="auto">Old Data</th>
<th class="TableHeadingCell" width="auto">New Data</th>
<th class="TableHeadingCell" width="8%">Result</th>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">3</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000100</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">5</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000300</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">45</td>
<td style="vertical-align: middle;" class="NumberCell">0x03002F00</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">5 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
</table>
</div>
<div class="Indentation"></div>
<table cellpadding="5" class="TestGroupHeadingBackground">
<tr>
<td>
<big class="Heading3">XXX</big>
</td>
</tr>
</table>
<div class="Indentation">
<p>Report is based on data obtained from comparing files XXX and XXX in folder USA.</p>
</div>
<div class="Indentation"></div>
<div class="Indentation">
<table cellpadding="5" class="ResultTable">
<tr>
<th class="TableHeadingCell" width="4%">Block ID</th>
<th class="TableHeadingCell" width="4%">Block Address</th>
<th class="TableHeadingCell" width="10%">Block Name</th>
<th class="TableHeadingCell" width="10%">Parameter Name</th>
<th class="TableHeadingCell" width="4%">Size</th>
<th class="TableHeadingCell" width="auto">Old Data</th>
<th class="TableHeadingCell" width="auto">New Data</th>
<th class="TableHeadingCell" width="8%">Result</th>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">3</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000100</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">5</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000300</td>
<td style="vertical-align: middle;" class="DefaultCell">Fbl_Global</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">45</td>
<td style="vertical-align: middle;" class="NumberCell">0x03002F00</td>
<td style="vertical-align: middle;" class="DefaultCell">ProdData</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">5 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
</table>
</div>
<table cellpadding="5" class="SubHeadingTable">
<tr>
<td>
<big class="Heading2">End of Report</big>
</td>
</tr>
</table>
<div class="Heading4" style="text-align=right;">Author: XXX</div>
<script>
window.onscroll = function()
{
myFunction()
};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction()
{
if (window.pageYOffset > sticky)
{
header.classList.add("sticky");
}
else
{
header.classList.remove("sticky");
}
}
</script>
</body>
When I run it in IE or chrome, the "Overall Report Passed" sticky text becomes fixed at top, but the entire screen flickers a moment when crossing that transistion point. I can fix it for my screen by giving padding-top:63px instead of auto (unsure what auto does) inside .sticky + .mid-container {} block
Can anybody suggest me how I can avoid this flickering altogether+make is common for all screen sizes + resolutions?
I'm using IE 11 + Mozilla Firefox. Flickering only occurs when scrolling down from the sticky text (scrolling from "Overall Report Passed" to "General Information")
What you doing is changing from position relative to absolute by adding this class .sticky which takes the header out of the document flow, at the same time .sticky + .mid-container is applied which applies position absolute on the div.mid-container that's the cause of the stuttering you see, if instead just apply a margin on the div.mid-container so when the header gets outside the document flow the elements don't react to that, so a margin-top equals to the height of the header should do it.
.sticky + .mid-container {
/* position:absolute; Removed */
/* Added : 39px is the height of your header. */
/* If this varies just include js to make it dynamic. */
margin-top:39px;
overflow: auto;
/* padding-top:auto; Removed : auto is not a valid value for padding */
}
window.onscroll = function() {
myFunction()
};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction() {
// i figured it should be '>='
if (window.pageYOffset >= sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: rgb(59, 75, 84);
font-family: arial, verdana, trebuchet, officina, sans-serif;
margin: 1;
}
.top-container {
background-color: #f1f1f1;
padding: 1px;
text-align: center;
}
.mid-container {
background-color: rgb(38, 52, 63);
padding: 1px;
text-align: left;
}
.header {
text-align: center;
padding: 5px 8px;
background: rgb(25, 165, 88);
color: #f1f1f1;
position: relative;
margin: 1;
z-index: 100;
}
.mid-container {
padding: 1px;
}
.sticky {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
.sticky+.mid-container {
margin-top: 39px;
overflow: auto;
}
table {
margin-bottom: 10px;
vertical-align: top;
border: 0;
border-spacing: 1px;
padding: 2px;
}
.HeadingTable {
width: 100%;
text-align: center;
margin-top: 15px;
margin-bottom: 30px;
margin-left: auto;
margin-right: auto;
background-color: rgb(220, 221, 222);
}
.SubHeadingTable {
width: 100%;
text-align: center;
margin-top: 15px;
margin-bottom: 25px;
background-color: rgb(220, 221, 222);
}
.ResultTable {
width: 100%;
text-align: left;
padding-right: 20px;
}
table.ResultTable td {
vertical-align: top;
}
.OverallResultTable {
width: 50%;
text-align: center;
margin-bottom: 20px;
margin-left: auto;
margin-right: auto;
font-weight: bold;
}
.TableHeadingCell {
background-color: rgb(179, 179, 179);
font-family: arial, verdana, trebuchet, officina, sans-serif;
font-weight: bold;
text-align: center;
}
.CellNoColor {
text-align: left;
vertical-align: top;
}
.DefaultCell {
background-color: rgb(229, 229, 229);
text-align: left;
}
.NumberCell {
background-color: rgb(229, 229, 229);
text-align: center;
min-width: 50px;
}
.PositiveResultCell {
text-align: center;
background-color: rgb(25, 165, 88);
}
.NegativeResultCell {
text-align: center;
background-color: rgb(240, 0, 0);
}
.WarningCell {
text-align: center;
background-color: rgb(255, 255, 0);
}
.NegativeResult {
background-color: rgb(240, 0, 0);
text-align: center;
font-weight: bold;
}
.PositiveResult {
background-color: rgb(25, 165, 88);
text-align: center;
font-weight: bold;
}
.Heading1 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 26px;
}
.Heading2 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 20px;
}
.Heading3 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 18px;
margin-bottom: 20px;
margin-top: 20px;
}
.Heading4 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 16px;
margin-top: 10px;
margin-bottom: 10px;
}
.Heading5 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 14px;
margin-top: 8px;
margin-bottom: 8px;
}
p {
Margin-bottom: 20px;
}
.TestGroupHeadingBackground {
background-color: rgb(179, 179, 179);
}
.Indentation {
margin-left: 20px;
}
<div class="top-container">
<h1>NVM Memory Comparision Report</h1>
</div>
<div class="header" id="myHeader">
<h2>Overall Report Passed</h2>
</div>
<div class="mid-container" style="margin-top: 0px;">
<h3>General Information</h3>
</div>
<div class="Heading4">Test Setup</div>
<div class="Indentation">
<table cellpadding="10">
<tbody>
<tr>
<td class="CellNoColor">Report Generation: </td>
<td class="CellNoColor">Success</td>
</tr>
<tr>
<td class="CellNoColor">File's Root Path: </td>
<td class="CellNoColor">New XXX Path: XXX</td>
</tr>
<tr>
<td class="CellNoColor">Configuration Comment: </td>
<td class="CellNoColor">XXX</td>
</tr>
<tr>
<td class="CellNoColor">XXX: </td>
<td class="CellNoColor">XXX</td>
</tr>
</tbody>
</table>
</div>
<div class="Heading4">Blocks Present in DataConfig</div>
<div class="Heading5">New Version:0042</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width="70%">
<tbody>
<tr>
<th class="TableHeadingCell" width="18%">Dataset Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;="">SparePart Number</th>
<th class="TableHeadingCell">Blocks Present</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Datasets</td>
<td class="DefaultCell" style="t" ext-align:center;="">All Sparepart Numbers</td>
<td class="DefaultCell"> Blocks 81, 99, 115, 120, 121, 133</td>
<td class="PositiveResult">Pass</td>
</tr>
</tbody>
</table>
</div>
<div class="Heading5">Old Version:0041</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width="70%">
<tbody>
<tr>
<th class="TableHeadingCell" width="18%">Dataset Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;="">SparePart Number</th>
<th class="TableHeadingCell">Blocks Present</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Datasets</td>
<td class="DefaultCell" style="t" ext-align:center;="">All Sparepart Numbers</td>
<td class="DefaultCell"> Blocks 81, 99, 115</td>
<td class="PositiveResult">Pass</td>
</tr>
</tbody>
</table>
</div>
<table cellpadding="5" class="SubHeadingTable">
<tbody>
<tr>
<td>
<big class="Heading2">Detailed Comparision Between FEE DUMPs</big>
</td>
</tr>
</tbody>
</table>
<div class="Indentation"></div>
<table cellpadding="5" class="TestGroupHeadingBackground">
<tbody>
<tr>
<td>
<big class="Heading3">XXX</big>
</td>
</tr>
</tbody>
</table>
<div class="Indentation">
<p>Report is based on data obtained from comparing files XXX and XXX in folder USA.</p>
</div>
<div class="Indentation"></div>
<div class="Indentation">
<table cellpadding="5" class="ResultTable">
<tbody>
<tr>
<th class="TableHeadingCell" width="4%">Block ID</th>
<th class="TableHeadingCell" width="4%">Block Address</th>
<th class="TableHeadingCell" width="10%">Block Name</th>
<th class="TableHeadingCell" width="10%">Parameter Name</th>
<th class="TableHeadingCell" width="4%">Size</th>
<th class="TableHeadingCell" width="auto">Old Data</th>
<th class="TableHeadingCell" width="auto">New Data</th>
<th class="TableHeadingCell" width="8%">Result</th>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">3</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000100</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">5</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000300</td>
<td style="vertical-align: middle;" class="DefaultCell">Fbl_Global</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">45</td>
<td style="vertical-align: middle;" class="NumberCell">0x03002F00</td>
<td style="vertical-align: middle;" class="DefaultCell">ProdData</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">5 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
</tbody>
</table>
</div>
<table cellpadding="5" class="SubHeadingTable">
<tbody>
<tr>
<td>
<big class="Heading2">End of Report</big>
</td>
</tr>
</tbody>
</table>
<div class="Heading4" style="text-align=right;">Author: XXX</div>
EDIT
Note i had to remove some of the markup so i can post the edit, it was exceeding the limit.
// we get the header height then apply it as marginTop to
// .mid-container
// removed the .sticky + .mid-container{} styling
// because we don't know the height of the header
// so we can't hard code it.
window.onscroll = function() {
myFunction()
};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction() {
// i figured it should be '>='
if (window.pageYOffset >= sticky) {
header.classList.add("sticky");
document.querySelector('.mid-container').style.marginTop = header.getBoundingClientRect().height + "px";
} else {
header.classList.remove("sticky");
document.querySelector('.mid-container').style.marginTop = "0px";
}
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: rgb(59, 75, 84);
font-family: arial, verdana, trebuchet, officina, sans-serif;
margin: 1;
}
.top-container {
background-color: #f1f1f1;
padding: 1px;
text-align: center;
}
.mid-container {
background-color: rgb(38, 52, 63);
padding: 1px;
text-align: left;
}
.header {
text-align: center;
padding: 5px 8px;
background: rgb(25, 165, 88);
color: #f1f1f1;
position: relative;
margin: 1;
z-index: 100;
/* For refrence */
height: 300px;
}
.mid-container {
padding: 1px;
}
.sticky {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
.sticky+.mid-container {
margin-top: 39px;
overflow: auto;
}
table {
margin-bottom: 10px;
vertical-align: top;
border: 0;
border-spacing: 1px;
padding: 2px;
}
.HeadingTable {
width: 100%;
text-align: center;
margin-top: 15px;
margin-bottom: 30px;
margin-left: auto;
margin-right: auto;
background-color: rgb(220, 221, 222);
}
.SubHeadingTable {
width: 100%;
text-align: center;
margin-top: 15px;
margin-bottom: 25px;
background-color: rgb(220, 221, 222);
}
.ResultTable {
width: 100%;
text-align: left;
padding-right: 20px;
}
table.ResultTable td {
vertical-align: top;
}
.OverallResultTable {
width: 50%;
text-align: center;
margin-bottom: 20px;
margin-left: auto;
margin-right: auto;
font-weight: bold;
}
.TableHeadingCell {
background-color: rgb(179, 179, 179);
font-family: arial, verdana, trebuchet, officina, sans-serif;
font-weight: bold;
text-align: center;
}
.CellNoColor {
text-align: left;
vertical-align: top;
}
.DefaultCell {
background-color: rgb(229, 229, 229);
text-align: left;
}
.NumberCell {
background-color: rgb(229, 229, 229);
text-align: center;
min-width: 50px;
}
.PositiveResultCell {
text-align: center;
background-color: rgb(25, 165, 88);
}
.NegativeResultCell {
text-align: center;
background-color: rgb(240, 0, 0);
}
.WarningCell {
text-align: center;
background-color: rgb(255, 255, 0);
}
.NegativeResult {
background-color: rgb(240, 0, 0);
text-align: center;
font-weight: bold;
}
.PositiveResult {
background-color: rgb(25, 165, 88);
text-align: center;
font-weight: bold;
}
.Heading1 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 26px;
}
.Heading2 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 20px;
}
.Heading3 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 18px;
margin-bottom: 20px;
margin-top: 20px;
}
.Heading4 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 16px;
margin-top: 10px;
margin-bottom: 10px;
}
.Heading5 {
font-family: arial, sans-serif;
font-weight: bold;
font-size: 14px;
margin-top: 8px;
margin-bottom: 8px;
}
p {
Margin-bottom: 20px;
}
.TestGroupHeadingBackground {
background-color: rgb(179, 179, 179);
}
.Indentation {
margin-left: 20px;
}
<div class="top-container">
<h1>NVM Memory Comparision Report</h1>
</div>
<div class="header" id="myHeader">
<h2>Overall Report Passed</h2>
</div>
<div class="mid-container" style="margin-top: 0px;">
<h3>General Information</h3>
</div>
<div class="Heading4">Test Setup</div>
<div class="Indentation">
<table cellpadding="10">
<tbody>
<tr>
<td class="CellNoColor">Report Generation: </td>
<td class="CellNoColor">Success</td>
</tr>
<tr>
<td class="CellNoColor">File's Root Path: </td>
<td class="CellNoColor">New XXX Path: XXX</td>
</tr>
<tr>
<td class="CellNoColor">Configuration Comment: </td>
<td class="CellNoColor">XXX</td>
</tr>
<tr>
<td class="CellNoColor">XXX: </td>
<td class="CellNoColor">XXX</td>
</tr>
</tbody>
</table>
</div>
<div class="Heading4">Blocks Present in DataConfig</div>
<div class="Heading5">New Version:0042</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width="70%">
<tbody>
<tr>
<th class="TableHeadingCell" width="18%">Dataset Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;="">SparePart Number</th>
<th class="TableHeadingCell">Blocks Present</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Datasets</td>
<td class="DefaultCell" style="t" ext-align:center;="">All Sparepart Numbers</td>
<td class="DefaultCell"> Blocks 81, 99, 115, 120, 121, 133</td>
<td class="PositiveResult">Pass</td>
</tr>
</tbody>
</table>
</div>
<div class="Heading5">Old Version:0041</div>
<div class="Indentation" style="float: none;">
<table cellpadding="5" width="70%">
<tbody>
<tr>
<th class="TableHeadingCell" width="18%">Dataset Name</th>
<th class="TableHeadingCell" width="12%" text-align:center;="">SparePart Number</th>
<th class="TableHeadingCell">Blocks Present</th>
<th class="TableHeadingCell" width="10%">Result</th>
</tr>
<tr>
<td class="TableHeadingCell">All Datasets</td>
<td class="DefaultCell" style="t" ext-align:center;="">All Sparepart Numbers</td>
<td class="DefaultCell"> Blocks 81, 99, 115</td>
<td class="PositiveResult">Pass</td>
</tr>
</tbody>
</table>
</div>
<table cellpadding="5" class="SubHeadingTable">
<tbody>
<tr>
<td>
<big class="Heading2">Detailed Comparision Between FEE DUMPs</big>
</td>
</tr>
</tbody>
</table>
<div class="Indentation"></div>
<table cellpadding="5" class="TestGroupHeadingBackground">
<tbody>
<tr>
<td>
<big class="Heading3">XXX</big>
</td>
</tr>
</tbody>
</table>
<div class="Indentation">
<p>Report is based on data obtained from comparing files XXX and XXX in folder USA.</p>
</div>
<div class="Indentation"></div>
<div class="Indentation">
<table cellpadding="5" class="ResultTable">
<tbody>
<tr>
<th class="TableHeadingCell" width="4%">Block ID</th>
<th class="TableHeadingCell" width="4%">Block Address</th>
<th class="TableHeadingCell" width="10%">Block Name</th>
<th class="TableHeadingCell" width="10%">Parameter Name</th>
<th class="TableHeadingCell" width="4%">Size</th>
<th class="TableHeadingCell" width="auto">Old Data</th>
<th class="TableHeadingCell" width="auto">New Data</th>
<th class="TableHeadingCell" width="8%">Result</th>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">3</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000100</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">5</td>
<td style="vertical-align: middle;" class="NumberCell">0x03000300</td>
<td style="vertical-align: middle;" class="DefaultCell">Fbl_Global</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">4 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
<tr>
<td style="vertical-align: middle;" class="NumberCell">45</td>
<td style="vertical-align: middle;" class="NumberCell">0x03002F00</td>
<td style="vertical-align: middle;" class="DefaultCell">ProdData</td>
<td style="vertical-align: middle;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="NumberCell">5 Bytes</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;font-family: Consolas,Monaco,Lucida Console,Courier New, monospace;" class="DefaultCell">XXX</td>
<td style="vertical-align: middle;" class="WarningCell">Value Changed</td>
</tr>
</tbody>
</table>
</div>
<table cellpadding="5" class="SubHeadingTable">
<tbody>
<tr>
<td>
<big class="Heading2">End of Report</big>
</td>
</tr>
</tbody>
</table>
<div class="Heading4" style="text-align=right;">Author: XXX</div>

how i can fix a table header when scroll

My table thead have 2 tr with diferents colspan and rowspan like this following picture:
<table id="header-fixed">
<thead>
<tr id="tr1" role="row" style="background-color: rgb(204, 9, 47);">
<th rowspan="2" colspan="1">Unidade</th>
<th rowspan="1" colspan="1">Orçado</th>
<th rowspan="1" colspan="1">Realizado</th>
<th rowspan="1" colspan="3">Atingimento no Resultado - Variação</th>
</tr>
<tr id="tr2" role="row" style="background-color: rgb(204, 9, 47);">
<th rowspan="1" colspan="1">Resultado</th>
<th rowspan="1" colspan="1">Resultado</th>
<th rowspan="1" colspan="1">Variação</th>
<th rowspan="1" colspan="1">%</th>
<th rowspan="1" colspan="1">Ating.</th>
</tr>
</thead>
...
</table>
I need fix the header of this table when scrolling, so, i found this code:
https://stackoverflow.com/a/4709775/8032896
This code almost work, when I scroll, the header is fixed, but column width is misfit like this picture.
Can someone help me?
try this example
td {
border-bottom: 1px solid #ccc;
padding: 5px;
text-align: left; /* IE */
}
td + td {
border-left: 1px solid #ccc;
}
th {
padding: 0 5px;
text-align: left; /* IE */
}
.header-background {
border-bottom: 1px solid black;
}
/* above this is decorative, not part of the test */
.fixed-table-container {
width: 50%;
height: 200px;
border: 1px solid black;
margin: 10px auto;
background-color: white;
/* above is decorative or flexible */
position: relative; /* could be absolute or relative */
padding-top: 30px; /* height of header */
}
.fixed-table-container-inner {
overflow-x: hidden;
overflow-y: auto;
height: 100%;
}
.header-background {
background-color: #D5ECFF;
height: 30px; /* height of header */
position: absolute;
top: 0;
right: 0;
left: 0;
}
table {
background-color: white;
width: 100%;
overflow-x: hidden;
overflow-y: auto;
}
.th-inner {
position: absolute;
top: 0;
line-height: 30px; /* height of header */
text-align: left;
border-left: 1px solid black;
padding-left: 5px;
margin-left: -5px;
}
.first .th-inner {
border-left: none;
padding-left: 6px;
}
/* for complex headers */
.complex.fixed-table-container {
padding-top: 60px; /* height of header */
overflow-x: hidden; /* for border */
}
.complex .header-background {
height: 60px;
}
.complex-top .th-inner {
border-bottom: 1px solid black;
width: 100%
}
.complex-bottom .th-inner {
top: 30px;
width: 100%
}
.complex-top .third .th-inner { /* double row cell */
height: 60px;
border-bottom: none;
background-color: #D5ECFF;
}
<div class="fixed-table-container complex">
<div class="header-background"> </div>
<div class="fixed-table-container-inner">
<table cellspacing="0">
<thead>
<tr class="complex-top">
<th class="first" colspan="2">
<div class="th-inner">First and Second</div>
</th>
<th class="third" rowspan="2">
<div class="th-inner">Third</div>
</th>
</tr>
<tr class="complex-bottom">
<th class="first">
<div class="th-inner">First</div>
</th>
<th class="second">
<div class="th-inner">Second</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>First</td>
<td>First</td>
<td>First</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>Last</td>
<td>Last</td>
<td>Last</td>
</tr>
</tbody>
</table>
</div>
</div>

How to achieve alternating row styles for a responsive table?

I think I need JavaScript to solve this but that's why I need help (I've only edited existing JavaScript - never created them).
I have two striped tables nest side-by-side that when viewed on a mobile device, the table on the right moves below the table on the left to look as one continuous table.
The problem is with the table striping only when viewed on a mobile device if the tbody row counts are an even number, I end up with two consecutive rows in the middle being the same color.
#media only screen and (max-width: 480px) {
.sizesTableContent {
display:block !important;
width:100% !important;
}
.hider {
display: none;
}
}
.sizesAsterisk {
width:100%;
border-collapse: collapse;
text-align: left;
font-family: arial, helvetica, sans-serif;
font-size: 14px;
font-weight: normal;
}
.hanging {
text-indent: -0.5em;
padding-left: 0.5em;
}
.sizesTableContent {
vertical-align: top;
}
.sizesTwoColumn {
width:100%;
border-collapse: collapse;
border-top: 1px solid #000000;
border-bottom: 1px solid #000000;
}
.sizes {
border-collapse: collapse;
white-space: nowrap;
width: 100%;
text-align: center;
font-family: arial, helvetica, sans-serif;
font-size: 14px;
font-weight: normal;
}
.sizes td:first-child {
text-align: left;
font-weight: bold;
}
.sizes th {
border-bottom: 1pt solid #000000;
vertical-align: bottom;
font-family: arial, helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
}
.sizes th:first-child {
text-align: left;
}
.sizes tbody tr:hover {
background: #D2DAE3;
}
.sizes tbody tr:nth-child(odd) {
background: #ffffcc;
}
.sizes tbody tr:nth-child(odd):hover {
background: #D2DAE3;
}
<table class="sizesAsterisk">
<tr>
<td>
<table class="sizesTwoColumn">
<tr>
<td class="sizesTableContent">
<table class="sizes" cellspacing="0" cellpadding="0">
<col width="33.3%">
<col width="33.3%">
<col width="33.4%">
<thead>
<tr>
<th>Size in
<br/>Inches</th>
<th>Lbs.
<br/>Per Ft</th>
<th>Est. Lbs.
<br/>Per 20' Bar</th>
</tr>
</thead>
<tbody>
<!--First column size data go between the tbody tags-->
<tr>
<td>1" x 1/4</td>
<td>.620</td>
<td>12.40</td>
</tr>
<tr>
<td>1-1/4 x 5/15</td>
<td>.960</td>
<td>19.20</td>
</tr>
<tr>
<td>1-1/2 x 5/16</td>
<td>1.180</td>
<td>23.60</td>
</tr>
</tbody>
</table>
</td>
<td class="hider" style="border-right: 1px solid #000000" width="14px"></td>
<td class="hider" width="14px"></td>
<td class="sizesTableContent">
<table class="sizes" cellspacing="0" cellpadding="0">
<col width="33.3%">
<col width="33.3%">
<col width="33.4%">
<thead class="hider">
<tr>
<th>Size in
<br/>Inches</th>
<th>Lbs.
<br/>Per Ft</th>
<th>Est. Lbs.
<br/>Per 20' Bar</th>
</tr>
</thead>
<tbody>
<!--Second column size data go between the tbody tags-->
<tr>
<td>1-1/2 x 7/16</td>
<td>1.560</td>
<td>31.20</td>
</tr>
<tr>
<td>1-3/4 x 7/16<span style="color:red"> *</span>
</td>
<td>1.910</td>
<td>38.20</td>
</tr>
<tr>
<td>2" x 1/2<span style="color:red"> *</span>
</td>
<td>2.587</td>
<td>51.74</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="hanging"><!--Asterisk notes go between the td tags-->
<span style="color:red">* </span>Also in 10' Lengths.
</td>
</tr>
</table>
You won't need JavaScript. Simply use some :last-child pseudo-selectors in your media query to change the presentation a little more in mobile view. This essentially switches the even/odd backgrounds of the 2nd table only in mobile view:
.sizesTableContent:last-child .sizes tbody tr:nth-child(odd) {
background: #fff;
}
.sizesTableContent:last-child .sizes tbody tr:nth-child(even) {
background: #ffffcc;
}
JSFiddle Example
#media only screen and (max-width: 480px) {
.sizesTableContent {
display:block !important;
width:100% !important;
}
.hider {
display: none;
}
.sizesTableContent:last-child .sizes tbody tr:nth-child(odd) {
background: #fff;
}
.sizesTableContent:last-child .sizes tbody tr:nth-child(even) {
background: #ffffcc;
}
}
.sizesAsterisk {
width:100%;
border-collapse: collapse;
text-align: left;
font-family: arial, helvetica, sans-serif;
font-size: 14px;
font-weight: normal;
}
.hanging {
text-indent: -0.5em;
padding-left: 0.5em;
}
.sizesTableContent {
vertical-align: top;
}
.sizesTwoColumn {
width:100%;
border-collapse: collapse;
border-top: 1px solid #000000;
border-bottom: 1px solid #000000;
}
.sizes {
border-collapse: collapse;
white-space: nowrap;
width: 100%;
text-align: center;
font-family: arial, helvetica, sans-serif;
font-size: 14px;
font-weight: normal;
}
.sizes td:first-child {
text-align: left;
font-weight: bold;
}
.sizes th {
border-bottom: 1pt solid #000000;
vertical-align: bottom;
font-family: arial, helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
}
.sizes th:first-child {
text-align: left;
}
.sizes tbody tr:hover {
background: #D2DAE3;
}
.sizes tbody tr:nth-child(odd) {
background: #ffffcc;
}
.sizes tbody tr:nth-child(odd):hover {
background: #D2DAE3;
}
<table class="sizesAsterisk">
<tr>
<td>
<table class="sizesTwoColumn">
<tr>
<td class="sizesTableContent">
<table class="sizes" cellspacing="0" cellpadding="0">
<col width="33.3%">
<col width="33.3%">
<col width="33.4%">
<thead>
<tr>
<th>Size in
<br/>Inches</th>
<th>Lbs.
<br/>Per Ft</th>
<th>Est. Lbs.
<br/>Per 20' Bar</th>
</tr>
</thead>
<tbody>
<!--First column size data go between the tbody tags-->
<tr>
<td>1" x 1/4</td>
<td>.620</td>
<td>12.40</td>
</tr>
<tr>
<td>1-1/4 x 5/15</td>
<td>.960</td>
<td>19.20</td>
</tr>
<tr>
<td>1-1/2 x 5/16</td>
<td>1.180</td>
<td>23.60</td>
</tr>
</tbody>
</table>
</td>
<td class="hider" style="border-right: 1px solid #000000" width="14px"></td>
<td class="hider" width="14px"></td>
<td class="sizesTableContent">
<table class="sizes" cellspacing="0" cellpadding="0">
<col width="33.3%">
<col width="33.3%">
<col width="33.4%">
<thead class="hider">
<tr>
<th>Size in
<br/>Inches</th>
<th>Lbs.
<br/>Per Ft</th>
<th>Est. Lbs.
<br/>Per 20' Bar</th>
</tr>
</thead>
<tbody>
<!--Second column size data go between the tbody tags-->
<tr>
<td>1-1/2 x 7/16</td>
<td>1.560</td>
<td>31.20</td>
</tr>
<tr>
<td>1-3/4 x 7/16<span style="color:red"> *</span>
</td>
<td>1.910</td>
<td>38.20</td>
</tr>
<tr>
<td>2" x 1/2<span style="color:red"> *</span>
</td>
<td>2.587</td>
<td>51.74</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="hanging">
<!--Asterisk notes go between the td tags-->
<span style="color:red">* </span>Also in 10' Lengths.</td>
</tr>
</table>

Categories