How to hover row with nth-child - html

I trying to build this table like this
When I hover on any row, the first two cells can't hover even though I have written :hover for all tr tags in the body
Help me pls, tks all!
.wrap-table {
width: calc(100% - 40px);
height: calc(100vh - 235px);
overflow: auto;
background-color: #fff;
margin-left: 10px;
padding-right: 20px;
}
.m-table {
width: 100%;
height: fit-content;
background-color: #fff;
}
.m-table thead th{
position: sticky;
top: 0;
background-color: #ECEEF1;
padding-left: 10px;
padding-right: 8px;
text-align: left;
height: 48px;
border-bottom: 1px solid #c7c7c7;
border-right: 1px solid #c7c7c7;
text-transform: uppercase;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
td:first-child, th:first-child {
position:sticky;
left:0;
z-index:1;
background-color:white;
}
td:nth-child(2),th:nth-child(2) {
position:sticky;
left:37px;
z-index:1;
background-color:white;
}
td:nth-child(12),th:nth-child(12) {
position:sticky;
right: -20px;
z-index:1;
border-left: 1px solid #c7c7c7;
background-color:white;
}
th:first-child , th:nth-child(2) , th:nth-child(12) {
z-index:3
}
.m-table th {
position: sticky;
top: 0;
background: #eee;
}
.m-table tbody tr,td {
height: 48px;
border-bottom: 1px solid #e5e5e5;
cursor: pointer;
}
.m-table tbody td {
padding: 0;
padding-left: 10px;
padding-right: 8px;
max-width: 150px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border-bottom: 1px solid #c7c7c7;
border-right: 1px dotted #c7c7c7;
}
.m-table tbody tr:hover {
background-color: #F3F8F8;
}
.m-table tbody tr:active {
background-color: #F4F5F6;
}
<table class="m-table" cellspacing="0">
<thead>
<tr>
<th class="sticky">
<input type="checkbox">
</th>
<th class="align-left sticky">MÃ NHÂN VIÊN</th>
<th class="align-left" style="width: 175px">tên nhân viên</th>
<th class="align-left">giới tính</th>
<th class="align-center">ngày sinh</th>
<th class="align-left" style="width: 150px">số cmnd</th>
<th class="align-left" style="width: 150px">chức danh</th>
<th class="align-left" style="width: 150px">tên đơn vị</th>
<th class="align-left" style="width: 120px">số tài khoản</th>
<th class="align-left">tên ngân hàng</th>
<th class="align-left">chi nhánh tk ngân hàng</th>
<th class="align-center sticky">chức năng</th>
</tr>
</thead>
<tbody>
<tr v-for="employee in employees" :key="employee.EmployeeId" :id="employee.EmployeeId">
<th>
<input type="checkbox">
</th>
<td class="sticky">NV0001</td>
<td>David Luiz</td>
<td>Male</td>
<td class="align-center">
01/01/1991
</td>
<td>376574567456</td>
<td>Teacher</td>
<td>School</td>
<td>465745747</td>
<td>Franch Bank</td>
<td>Paris</td>
<td class="sticky">
<MOption />
</td>
</tr>
</tbody>
</table>

you must remove "background-color: white" from this part of your code
td:nth-child(2),
th:nth-child(2) {
position: sticky;
left: 37px;
z-index: 1;
background-color: white;
}
or instead, you can change this part of your code to this
.m-table tbody tr:hover td {
background-color: #f3f8f8;
}

This rule has greater specificity, so it applies first and sets the background-color to white.
td:nth-child(2),th:nth-child(2) {
position:sticky;
left:37px;
z-index:1;
background-color:white;
}

Related

Table is not scrollable

I coded a table and this table has so much information in it that if the page is on 100% more than half of the table is missing.
I hope you can help me. You have to add more of the table cells to recreate it.
body {
min-height: 100vh;
background-color: var(--body-color);
transition: var(--tran-05);
background-color: #18191a;
--body-color: #18191a;
--sidebar-color: #242526;
--primary-color: #3a3b3c;
--primary-color-light: #3a3b3c;
--toggle-color: #fff;
--text-color: #ccc;
}
table.content {
border-collapse: collapse;
margin: auto;
min-width: 400px;
border-radius: 5px 5px 0 0;
justify-content: center;
width: 75%;
padding: 2%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: #201f1b;
}
table.content thead tr {
background-color: #403f46;
color: white;
font-weight: bold;
text-align: left;
}
table.content th,
table.content td {
padding: 12px 16px;
}
table.content tbody tr {
border-bottom: 1px solid #ccc;
}
table.content tbody tr:last-of-type {
border-bottom: 2px solid #403f46;
}
table.content tbody tr.active {
font-weight: bold;
color: #403f46;
}
<table class="content">
<thead>
<tr>
<th>ServerID</th>
<th>Server Owner</th>
<th>Premium Server</th>
<th>Dev Server</th>
</tr>
</thead>
<tbody>
<tr>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
</tr>
</tbody>
</table>
The problem is because of this:
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
it calculates -50% on the y-axis, which results in a cut. This works fine, but not for long elements.
Instead of this, just using a div as a wrapper around the table.
Update your code like the following:
Html:
<div class="wrapper">
<table class="content">
<thead>
<tr>
<th>ServerID</th>
<th>Server Owner</th>
<th>Premium Server</th>
<th>Dev Server</th>
</tr>
</thead>
<tbody>
<tr>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
</tr>
</tbody>
</table>
</div>
css:
div.wrapper {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
table.content {
border-collapse: collapse;
margin: auto;
min-width: 400px;
border-radius: 5px 5px 0 0;
width: 75%;
padding: 2%;
color: #f9f9f9;
}
now it should work correctly.

HTML CSS Table border-radius property not applying

I have a table in this format:
.main-table {
margin-top: 1vw;
margin-left: 1vw;
height: 30vw;
overflow-y: auto;
overflow-x: hidden;
}
table {
border-collapse: separate;
border-radius: 3vw;
border-spacing: 0;
margin-top: 1vw;
width: 87vw;
}
td,
th {
border: none;
}
th {
height: 2vw;
background: #deb724;
font-weight: bold;
}
td {
height: 3vw;
background: white;
text-align: center;
}
tr td:hover {
background: #d5d5d5;
}
<div class="main-table">
<table>
<thead>
<tr>
<th> Hello </th>
<th> World </th>
</tr>
</thead>
<tbody>
<tr>
<td> Wow look </td>
<td> What is this </td>
</tr>
</tbody>
</table>
</div>
There is a border-radius property on the table, however it's not applying. I have been looking up and all I can find is set border-collapse as separate, but that didn't do it either. Any help?
Add overflow: hidden to table.
.main-table {
margin-top: 1vw;
margin-left: 1vw;
height: 30vw;
overflow-y: auto;
overflow-x: hidden;
}
table {
border-collapse: separate;
border-radius: 3vw;
border-spacing: 0;
margin-top: 1vw;
width: 87vw;
overflow: hidden;
}
td,
th {
border: none;
}
th {
height: 2vw;
background: #deb724;
font-weight: bold;
}
td {
height: 3vw;
background: white;
text-align: center;
}
tr td:hover {
background: #d5d5d5;
}
<div class="main-table">
<table>
<thead>
<tr>
<th> Hello </th>
<th> World </th>
</tr>
</thead>
<tbody>
<tr>
<td> Wow look </td>
<td> What is this </td>
</tr>
</tbody>
</table>
</div>
Actually it is applied, but overflows it outside. We can see that by adding border to table in the below snippet. That's why we should add overflow: hidden
.main-table {
margin-top: 1vw;
margin-left: 1vw;
height: 30vw;
overflow-y: auto;
overflow-x: hidden;
}
table {
border-collapse: separate;
border-radius: 3vw;
border-spacing: 0;
margin-top: 1vw;
width: 87vw;
border: 2px solid red;
}
td,
th {
border: none;
}
th {
height: 2vw;
background: #deb724;
font-weight: bold;
}
td {
height: 3vw;
background: white;
text-align: center;
}
tr td:hover {
background: #d5d5d5;
}
<div class="main-table">
<table>
<thead>
<tr>
<th> Hello </th>
<th> World </th>
</tr>
</thead>
<tbody>
<tr>
<td> Wow look </td>
<td> What is this </td>
</tr>
</tbody>
</table>
</div>

Stylesheet in <link> tag will not render in Firefox or IE

I have an HTML document with a stylesheet referenced in a link tag. The character set is UTF-8 and is defined in the HTML and CSS files. In Chrome and Microsoft Edge, the CSS renders as it should, however in Firefox and IE it doesn't load it. There aren't any errors in the Console of Developer tools and no compilation errors in the IDE I am using.
I can go directly to the CSS file using the absolute file path in the URL bar and it will display the contents of the file, and it will render the HTML just fine. The CSS will render when I enclose it in style tags in the HTML file itself. However, I want to link tag it for organization.
I cannot find the solution anywhere even though many people have had this issue. I'm wondering if there is a known solution to this that could help me.
Here is the HTML:
<!DOCTYPE html>
<html>
<head>
<title>#</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="\css\core-test.css" media="screen">
</head>
<body>
<div class="container">
<nav class="navbar">
<a>#</a>
</nav>
<div class="table-box">
<div class="table-body">
<table id="main-table" class="table">
<thead>
<tr>
<th>TIME</th>
<th>TICKER</th>
<th>CALL/PUT</th>
<th>EXPIRY</th>
<th>STRIKE</th>
<th>SPOT</th>
<th>PRICE</th>
<th>SIZE</th>
<th>TOTAL</th>
<th>OI</th>
<th>IV</th>
<th><button id="filterbtn" class="filterbtn fa fa-filter"></button></th>
</tr>
</thead>
<tbody>
<tr>
<td>00:12:34</td>
<td class="btc-color">BTC</td>
<td class="put-color">PUT</td>
<td>4/28</td>
<td>$7800</td>
<td>$7219</td>
<td>₿0.031</td>
<td>20</td>
<td class="put-color">₿62</td>
<td>1120</td>
<td>60.9%</td>
<td><button class="chartbtn fa fa-line-chart"></button></td>
</tr>
<tr>
<td>00:12:34</td>
<td class="btc-color">BTC</td>
<td class="put-color">PUT</td>
<td>4/28</td>
<td>$7800</td>
<td>$7219</td>
<td>₿0.031</td>
<td>20</td>
<td class="put-color">₿62</td>
<td>1120</td>
<td>60.9%</td>
<td><button class="chartbtn fa fa-line-chart"></button></td>
</tr>
</tbody>
</table>
<div id="option-modal" class="option-modal">
<div id="option-modal-box" class="option-modal-box">
<span id="closebtn" class="closebtn">×</span>
<div id="option-modal-header" class="option-modal-header">
<a id="option-modal-header-title" class="btc-color option-modal-header-title">BITCOIN</a>
</div>
<div id="option-modal-body" class="option-modal-body">
<div id="chart-box" class="chart-box">
<div class="box-header">
<a class="box-title">Chart</a>
</div>
<div style="background-color: gray;" class="box-body">
<a>chart-box</a>
</div>
</div>
<div id="orderbook-box" class="orderbook-box">
<div class="box-header">
<a class="box-title">Orderbook</a>
</div>
<div class="box-body">
<div class="orderbook-bid-body">
<table id="orderbook-bid-table" class="orderbook-bid-table">
<thead>
<tr>
<th>TOTAL</th>
<th>SIZE</th>
<th>BID</th>
</tr>
<tbody>
<tr>
<td>1.0</td>
<td>1.0</td>
<td class="call-color">0.031</td>
</tr>
<tr>
<td>1.0</td>
<td>1.0</td>
<td class="call-color">0.031</td>
</tr>
</tbody>
</thead>
</table>
</div>
<div class="orderbook-ask-body">
<table class="orderbook-ask-table">
<thead>
<tr>
<th>ASK</th>
<th>SIZE</th>
<th>TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="put-color">0.032</td>
<td>1.0</td>
<td>1.0</td>
</tr>
<tr>
<td class="put-color">0.032</td>
<td>1.0</td>
<td>1.0</td>
</tr>
</table>
</div>
</div>
</div>
<div id="stat-box" class="stat-box">
<div class="box-header">
<a class="box-title">Greeks</a>
</div>
<div class="box-body">
<table id="greek-table" class="option-modal-table">
<thead>
<tr>
<th>MARK</th>
<th>OI</th>
<th>IV</th>
<th>DELTA</th>
<th>THETA</th>
<th>VEGA</th>
<th>GAMMA</th>
</tr>
</thead>
<tbody>
<tr>
<td id="mark-greek">0.031</td>
<td id="oi-greek">1120.0</td>
<td id="iv-greek">60.9%</td>
<td id="delta-greek">-0.2</td>
<td id="thelta-greek">-9.0</td>
<td id="vega-greek">1.23</td>
<td id="gamma-greek">0.00012</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="trade-box" class="trade-box">
<div class="box-header">
<a class="box-title">Recent Trades</a>
</div>
<div class="box-body">
<table id="trade-table" class="option-modal-table">
<thead>
<tr>
<th>PRICE</th>
<th>IV</th>
<th>SIZE</th>
<th>TIME</th>
</tr>
</thead>
<tbody>
<tr>
<td>0.032</td>
<td>60.9%</td>
<td>1</td>
<td class="call-color">00:12:34</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var optionModal = document.getElementById("option-modal");
var chartButton = document.getElementsByClassName("chartbtn");
var closeButton = document.getElementById("closebtn");
function openChart() {
optionModal.style.display = "block";
}
for (var i = 0; i < chartButton.length; i++) {
chartButton[i].addEventListener("click", openChart);
}
window.onclick = function(event) {
if (event.target == optionModal) {
optionModal.style.display = "none";
}
}
closeButton.onclick = function(event) {
if (event.target == closeButton) {
optionModal.style.display = "none";
}
}
</script>
</html>
Here is the CSS:
#import url(https://fonts.googleapis.com/css2?family=Overpass&display=swap);
#import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css);
#charset "utf-8";
:root {
--bg: #060c17;
--item-bg: #0c1427;
--main-font-color: white;
--border: #262f43;
--th-bg: black;
--th-font: #7886a1;
--btc: #ff8133;
--eth: #106fb7;
--call: #10b759;
--put: #ff3366;
--main-font: 'Overpass', sans-serif;
}
.container {
display: flex;
flex-direction: column;
position: absolute;
align-items: center;
justify-content: center;
top: 0;
right: 0;
left: 0;
bottom: 0;
margin: 0;
background-color: var(--bg);
}
.navbar {
position: fixed;
padding: 20px;
top: 0;
right: 0;
left: 0;
width: 100%;
text-align: center;
background: var(--item-bg);
border-bottom: 1px solid var(--border);
}
.navbar a {
color: var(--main-font-color);
font-size: 20px;
font-family: var(--main-font);
}
.table-box {
display: flex;
border-radius: 0.25rem;
margin-top: 75px;
margin-bottom: 1px;
height: 100%;
width: 99%;
background-color: var(--item-bg);
border: 1px solid var(--border);
overflow: hidden;
}
.filterbtn {
color: var(--th-font);
background-color: var(--th-bg);
font-size: 14px;
border: none;
cursor: pointer;
}
.table-body {
position: relative;
margin-top: 40px;
width: 100%;
overflow: auto;
border-top: 1px solid var(--border);
}
.table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
font-family: var(--main-font);
}
.table thead {
color: var(--th-font);
}
.table tbody {
color: var(--main-font-color);
}
.table thead th {
position: sticky;
top: 0;
background-color: var(--th-bg);
}
.chartbtn {
font-size: 14px;
border: none;
border-radius: 0.25rem;
cursor: pointer;
color: var(--th-font);
background-color: var(--th-bg);
}
.table thead th,
.table tbody td {
text-align: left;
padding: 10px 10px;
border-bottom: 1px solid var(--border);
}
.table tbody tr:nth-child(even) {
background-color: var(--bg);
}
.btc-color {
color: var(--btc);
}
.eth-color {
color: var(--eth);
}
.call-color {
color: var(--call);
}
.put-color {
color: var(--put);
}
.option-modal {
display: block;
position: fixed;
z-index: 1;
padding-top: 20px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}
.option-modal-box {
display: flex;
margin: auto;
height: 95%;
width: 90%;
background-color: var(--item-bg);
border: 1px solid var(--border);
border-radius: 0.25rem;
overflow: hidden;
}
.closebtn {
padding-top: 0.5%;
right: 6%;
cursor: pointer;
font-size: 20px;
font-family: var(--main-font);
position: fixed;
color: var(--main-font-color);
}
.option-modal-header {
position: fixed;
margin: 5px;
}
.option-modal-header-title {
position: sticky;
font-family: var(--main-font);
font-size: 20px;
}
.option-modal-body {
display: flex;
flex-direction: row;
justify-content: space-evenly;
flex-wrap: wrap;
margin-top: 40px;
height: 90%;
width: 100%;
background-color: var(--item-bg);
overflow: auto;
}
.option-modal-body div {
min-width: 50%;
}
.orderbook-bid-body {
display: inline-table;
}
.orderbook-bid-table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
font-family: var(--main-font);
}
.orderbook-bid-table thead {
color: var(--th-font);
}
.orderbook-bid-table tbody {
color: var(--main-font-color);
}
.orderbook-bid-table thead th {
position: sticky;
top: 0;
background-color: var(--th-bg);
}
.orderbook-bid-table thead th,
.orderbook-bid-table tbody td {
text-align: center;
padding: 5px 0px;
border-bottom: 1px solid var(--border);
border-right: 1px solid var(--border);
border-collapse: collapse;
}
.orderbook-bid-table tbody tr:nth-child(even) {
background-color: var(--bg);
}
.orderbook-ask-body {
float: right;
}
.orderbook-ask-table {
position: relative;
padding-bottom: 10px;
width: 100%;
border-collapse: collapse;
font-size: 14px;
font-family: var(--main-font);
}
.orderbook-ask-table thead {
color: var(--th-font);
}
.orderbook-ask-table tbody {
color: var(--main-font-color);
}
.orderbook-ask-table thead th {
position: sticky;
top: 0;
background-color: var(--th-bg);
}
.orderbook-ask-table thead th,
.orderbook-ask-table tbody td {
text-align: center;
padding: 5px 0px;
border-bottom: 1px solid var(--border);
border-right: 1px solid var(--border);
border-left: 1px solid var(--border);
}
.orderbook-ask-table tbody tr:nth-child(even) {
background-color: var(--bg);
}
.option-modal-table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
font-family: var(--main-font);
}
.option-modal-table thead {
color: var(--th-font);
}
.option-modal-table tbody {
color: var(--main-font-color);
}
.option-modal-table thead th {
position: sticky;
top: 0;
background-color: var(--th-bg);
}
.option-modal-table thead th,
.option-modal-table tbody td {
text-align: center;
padding: 5px 0px;
border-bottom: 1px solid var(--border);
}
.option-modal-table tbody tr:nth-child(even) {
background-color: var(--bg);
}
#media screen and (max-width: 800px) {
.chart-box {
width: 100%;
}
.orderbook-box {
width: 100%;
}
.stat-box {
order: 4;
width: 100%;
}
.trade-box {
width: 100%;
order: 3;
}
}
.chart-box {
height: 50%;
overflow: hidden;
}
.orderbook-box {
height: 50%;
overflow: hidden;
}
.stat-box {
height: 49%;
overflow: hidden;
}
.trade-box {
height: 49%;
overflow: hidden;
}
.box-header {
height: 6%;
padding: 5px;
}
.box-title {
color: var(--main-font-color);
font-family: var(--main-font);
font-size: 16px;
margin: auto;
}
.box-body {
border: 1px solid var(--border);
height: 89%;
overflow: auto;
}
Could the backslashes be the problem?
<link rel="stylesheet" type="text/css" href="/css/core-test.css" media="screen">
Try changing them to forward slashes.

Responsive table, unable to line up thead and tbody

I have created a table however I cannot get the <thead>s to line up with the <tbody>s.
The table is responsive and works as I want it to when resized, however it's the initial screen size that is the issue.
I have added float:left to the <thead>s so they align properly instead of overlapping each other and would like the table data to a-line in the same way.
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background: #f8f8f8;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table td {
font-size: 0.60em;
}
table th {
font-size: .60em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td:before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
#table-wrapper {
position: relative;
}
#table-scroll {
overflow: auto;
}
#table-wrapper table {
width: 100%;
}
#table-wrapper table * {
color: black;
font-size: 12px;
}
#table-wrapper table thead th .text {
text-align: center;
}
}
<div class="col-12 offset-0">
<div style="overflow-x:auto">
<div id="table-wrapper">
<div id="table-scroll">
<table class="table table-striped" border="0" cellspacing="0" cellpadding="0" align="center">
<h4>Success Stream</h4>
<thead style="float:left">
<tr>
<th scope="col">Year</th>
<th scope="col">{{n1}}'s age</th>
<th scope="col">{{n2}}'s age</th>
<th scope="col">Income</th>
<th scope="col">Personal Contribution to Pension</th>
<th scope="col">Company Contribution to Pension</th>
<th scope="col">Personal Contribution to ISA</th>
<th scope="col">Expenses</th>
<th scope="col">Cash Flow</th>
<th scope="col">Growth of Pension</th>
<th scope="col">Growth of ISA</th>
<th scope="col">Growth of Other</th>
<th scope="col">Withdrawals from Pension</th>
<th scope="col">Withdrawals from ISA</th>
<th scope="col">Withdrawals from Other</th>
<th scope="col">Pension Total</th>
<th scope="col">ISA Total</th>
<th scope="col">Other Total</th>
<th scope="col">Full Total</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Year"> 2018</td>
<td data-label="{{n1}}'s age">55</td>
<td data-label="{{n2}}'s age">55</td>
<td data-label="Income">57,000</td>
<td data-label="Personal Contribution to Pension">5,000</td>
<td data-label="Company Contribution to Pension">0</td>
<td data-label="Personal Contribution to ISA">0</td>
<td data-label="Expenses">50,500</td>
<td data-label="Cash Flow">1,500</td>
<td data-label="Growth of Pension">57,737</td>
<td data-label="Growth of ISA">0</td>
<td data-label="Growth of Other">0</td>
<td data-label="Withdrawals from Pension">0</td>
<td data-label="Withdrawals from ISA">0</td>
<td data-label="Withdrawals from Other">0</td>
<td data-label="Pension Total">862,737</td>
<td data-label="ISA Total">1</td>
<td data-label="Other Total">1,501</td>
<td data-label="Full Total">864,239</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Instead of using float:left for thead just change
table {
table-layout: fixed;
}
to
table {
table-layout: auto;
}

Fixed table row in table

I am trying to fix the position of first <tr> in <table> but it now looks like this:
but I would like to have it like this:
I tried:
<table id="myHeader" class="table table-striped table-hover table-bordered table-responsive"><tbody>
<tr style="position: fixed;">
<th>Sr.</th>
<th>Question</th>
<th class="mobiile">Your Answer</th>
<th>Right Answer</th>
<th>Marks</th>
</tr>
document.getElementById('theTable').addEventListener('scroll', scrollHeader);
function scrollHeader(e){
var table = e.currentTarget,
thead = table.getElementsByTagName('thead')[0];
thead.scrollLeft = table.scrollLeft;
}
table {
font-family:Arial, Helvetica, sans-serif;
color:#666;
font-size:15px;
background:#eaebec;
border:#ccc 1px solid;
border-radius:3px;
border-collapse:collapse; border-spacing: 0;
box-shadow: 0 1px 2px #d1d1d1;
display: block;
overflow: auto;
max-height: 200px;
width:425px;
}
table thead {
z-index: 1; /* put on top of other rows */
display: block;
position: fixed;
/* make sure this header width is same as table */
max-width: 500px;
overflow-y: auto; /* use auto so scrollbars only appear if they need to*/
overflow-x: hidden;
}
thead tr td {
background: #eaebec;
width: 65px;
min-width: 65px;
}
table tbody {
display: block;
padding-top: 40px;
}
table th {
padding:2px 2px 2px 2px;
border-top:0;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
background: #ededed;
}
table tr {
text-align: center;
}
/* only using !important to override your styles below */
table td {
margin-left: 0 !important;
width: 65px !important;
padding:2px 2px 2px 2px;
border-top:0;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
}
table tr:hover td {
background: #F7FE2E;
}
table tr, table td {
width: 65px;
min-width: 65px;
}
<div id='container'>
<div id='content'><h3><font color='blue'>Listcode - MP</font></h3>
<div id='wrapper'>
<table id="theTable"><thead><tr><td>Julian Date</td>
<td>Records</td>
<td>Sales</td>
<td>CPO</td>
<td>2006 Records</td>
<td>2006 Deals</td>
</tr></thead>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
<tr><td>229</td><td>39784</td><td>0</td><td>10,542.76</td><td>0</td><td>39784</td></tr>
</table></div></div></div>