I have a table like in the picture:
What I am trying to achieve is I want the total part sticky on the table and Math, History and Biology etc. should be able to scroll right. S now the Math is next to the Total but I want History or Biology should be able to next to Total also.
Until now my code is like this:
.last-workouts .last-workout-table {
border-radius: 20px;
}
.last-workouts table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
.last-workouts table .tests:not(:last-child) {
border-bottom: 1px solid #050a6c;
}
.last-workouts .test {
background-color: #00bad6;
text-align: center;
color: #FFFFFF;
padding: 1rem 0;
width: 20%;
}
.last-workouts .test .number-test,
.last-workouts .test .type-test {
font-weight: bold;
}
.last-workouts .result {
margin: 0;
padding: 0;
text-align: center;
width: 12%;
background-color: #F0F0F0;
}
.last-workouts .inner-table {
border: none;
}
.last-workouts .inner-table tr:not(:last-child) {
border-bottom: 1px solid #a9a9a9;
}
.last-workouts .total {
color: #00bad6;
font-weight: bold;
padding: .25rem;
}
.last-workouts .inner-table .box td {
padding: 0.5rem;
border: 1px solid #a9a9a9;
}
.last-workouts .inner-table .box .bold {
font-weight: bold;
}
.last-workouts .inner-table .box .bold.red {
color: red;
}
.last-workouts .inner-table .box div {
padding: .5rem;
}
.last-workouts .lessons {
margin: 0;
padding: 0;
text-align: center;
width: 12%;
}
.last-workouts .lessons:not(:last-child) {
border-right: 2px solid #000000;
}
<div class="last-workouts">
<div style="overflow-x:auto;" class="last-workout-table">
<table>
<tr class="tests">
<td class="test">
<div class="number-test">TYT-1</div>
<div class="type-test">Genel Deneme</div>
<div class="date">30.08.2021</div>
</td>
<td class="result">
<div class="total">
Toplam
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
<td class="lessons">
<div class="total">
Matematik
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
<td class="lessons">
<div class="total">
Turkce
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
<td class="lessons">
<div class="total">
Tarih
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
So how do you think I can achieve this?
Thanks
Nest .test and .result in an inner table and add position: sticky; left: 0; to the outer td.
.last-workouts .last-workout-table {
border-radius: 20px;
}
.last-workouts table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
.last-workouts table .tests:not(:last-child) {
border-bottom: 1px solid #050a6c;
}
.last-workouts .test {
background-color: #00bad6;
text-align: center;
color: #FFFFFF;
padding: 1rem 0;
width: 20%;
}
.last-workouts .test .number-test,
.last-workouts .test .type-test {
font-weight: bold;
}
.last-workouts .result {
margin: 0;
padding: 0;
text-align: center;
width: 12%;
background-color: #F0F0F0;
}
.last-workouts .inner-table {
border: none;
}
.last-workouts .inner-table tr:not(:last-child) {
border-bottom: 1px solid #a9a9a9;
}
.last-workouts .total {
color: #00bad6;
font-weight: bold;
padding: .25rem;
}
.last-workouts .inner-table .box td {
padding: 0.5rem;
border: 1px solid #a9a9a9;
}
.last-workouts .inner-table .box .bold {
font-weight: bold;
}
.last-workouts .inner-table .box .bold.red {
color: red;
}
.last-workouts .inner-table .box div {
padding: .5rem;
}
.last-workouts .lessons {
margin: 0;
padding: 0;
text-align: center;
width: 12%;
}
.last-workouts .lessons:not(:last-child) {
border-right: 2px solid #000000;
}
<div class="last-workouts">
<div style="overflow-x:auto;" class="last-workout-table">
<table>
<tr class="tests">
<td style="position: sticky; left: 0;">
<table>
<td class="test">
<div class="number-test">TYT-1</div>
<div class="type-test">Genel Deneme</div>
<div class="date">30.08.2021</div>
</td>
<td class="result">
<div class="total">
Toplam
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
</table>
</td>
<td class="lessons">
<div class="total">
Matematik
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
<td class="lessons">
<div class="total">
Turkce
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
<td class="lessons">
<div class="total">
Tarih
</div>
<table class="inner-table">
<tr class="box">
<td>S</td>
<td>D</td>
<td>Y</td>
<td>B</td>
<td class="bold">Net</td>
<td class="bold">Puan</td>
</tr>
<tr class="box">
<td>115</td>
<td>80</td>
<td>6</td>
<td>16</td>
<td class="bold red">17.48</td>
<td class="bold red">490,54</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
Related
This is my code, I want to reduce the width of all the rows in table (except for first table) when the size of screen is more than 1000px. I tried this but this media query is not seem to be working. And also I want the bottom border of the table to be rounded, with the code I tried except for the left-most all the border-bottom radius is getting rounded
Can anyone tell what I am missing?
I have read many answers none of them seem to be working
#media screen and (min-width: 1000px) {
.table-container {
float: left;
width: 15%;
}
.table-container:first-of-type {
width: 40%;
}
}
.table_container {
float: left;
width: 25%;
}
.container::after {
content: "";
clear: both;
display: table;
}
table {
margin: 0 auto;
border-radius: 10px;
}
tr {
padding: 15px;
text-align: center;
}
td {
color: black;
text-align: center;
vertical-align: middle;
border: 1px double white;
height: 50px;
background-color: grey;
width: 272px;
}
.sub_text {
font-size: 12px;
font-style: italic;
color: #0071ce;
font-weight: 100;
}
th {
background-color: black;
text-align: center;
padding: 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
color: white;
font-weight: bold;
height: 70px;
}
.header {
color: #0071ce;
font-weight: bold;
padding: 10px;
}
.wrapper {
text-align: center;
margin-top: 20px;
}
table tr:last-child td:first-child {
border-bottom-left-radius: 10px;
}
table tr:last-child td:last-child {
border-bottom-right-radius: 10px
<div class="table_container">
<table>
<thead>
<tr>
<th colspan="2">Cost</th>
</tr>
<tr>
</thead>
<td class="header" rowspan="4">Your cost per biweekly paycheck<br>
<span class="sub_text">Tobacco-free rates shown</span>
</td>
<td> emp Only</td>
<tr>
<td> emp + Spouse/partner</td>
</tr>
<tr>
<td> emp + child(ren)</td>
</tr>
<tr>
<td> emp + family</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2"> Org’s annual max contribution<br>
<span class="sub_text">
</span>
</td>
<td> emp Only</td>
<tr>
<td> emp + dependent(s)</td>
</tr>
</tr>
<tr>
<td class="header" rowspan="2">Annua deductible<br>
<span class="sub_text">in-network care</span>
</td>
<td> emp Only</td>
<tr>
<td> emp + dependent(s)</td>
</tr>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<tr>
<th>Tab B<input type="checkbox" id="2" name="table2" value="table2"></th>
</tr>
<tr>
<td>A</td>
</tr>
<tr>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
<tr>
<td>D</td>
</tr>
<tr>
<td>E</td>
</tr>
<tr>
<td>F</td>
</tr>
<tr>
<td>G</td>
</tr>
<tr>
<td>H</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<tr>
<th>Tab B<input type="checkbox" id="2" name="table2" value="table2"></th>
</tr>
<tr>
<td>A</td>
</tr>
<tr>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
<tr>
<td>D</td>
</tr>
<tr>
<td>E</td>
</tr>
<tr>
<td>F</td>
</tr>
<tr>
<td>G</td>
</tr>
<tr>
<td>H</td>
</tr>
</table>
</div>
<div class="table_container">
<table id="table2" class="checkboxdiv">
<tr>
<th>Tab B<input type="checkbox" id="2" name="table2" value="table2"></th>
</tr>
<tr>
<td>A</td>
</tr>
<tr>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
<tr>
<td>D</td>
</tr>
<tr>
<td>E</td>
</tr>
<tr>
<td>F</td>
</tr>
<tr>
<td>G</td>
</tr>
<tr>
<td>H</td>
</tr>
</table>
</div>
#media screen and (min-width: 800px) {
.table-container {
float: left;
width: 15%;
}
}
You were using .table-container, not .table_container from above. Just tried this and it works as expected. Also make sure to add it to the bottom of the stylesheet.
#media screen and (min-width: 1000px) {
.table_container {
float: left;
width: 15%;
}
.table_container:first-of-type() {
width: 40%;
}
}
For the bottom-border-radius, if you're trying to avoid using classes this is a solution that works if your table is staying the same size. If you add columns you would have to adjust tr:nth-of-type(7) to the appropriate number.
table tr:last-child td:first-child {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px
}
.table_container:nth-of-type(1) tr:last-child td:first-child {
border-bottom-left-radius: 0;
}
.table_container:nth-of-type(1) tr:nth-of-type(7) td:first-child {
border-bottom-left-radius: 10px;
}
I've created a basic HTML table yet I can't seem to get the top <th> element to span 100% width of it's parent <tr> element (and ultimately the <table> element).
.my-card-table {
width: 100%;
border: 1px solid #D9D7D6;
table-layout: fixed!important;
}
.table-top-heading {
display: block;
text-align: center;
}
.my-card-table-heading {
background-color: #E9E9E9!important;
font-family: "Proxima Nova Regular";
color: #000000;
font-size: 1rem;
padding: 10px 5px 10px 5px;
}
.my-card-table-heading-inner {
background-color: #E9E9E9!important;
font-family: "Proxima Nova Regular";
color: #000000;
font-size: 1rem;
text-align: left;
padding: 10px 0 10px 30px
}
.my-card-table-row-grey {
background-color: #F2F3F3!important;
padding: 10px!important;
}
.my-card-table-row-white {
background-color: #ffffff!important;
padding: 10px!important;
}
..my-table-td {
text-align: left;
padding-left: 30px;
}
.my-card-link {
color: #0e5b8b;
}
.my-card-link:hover {
font-family: "Proxima Nova Bold";
color: #0e5b8b;
}
.my-card-link-2 {
color: #212529;
}
<table class="my-card-table">
<tr class="table-top-heading">
<th class="table-top-heading-header">HelloWorld</th>
</tr>
<tr class="my-card-table-heading">
<th class="my-card-table-heading-inner">Teachers</th>
<th class="my-card-table-heading-inner">School</th>
<th class="my-card-table-heading-inner">Status</th>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 1</td>
<td class="my-table-td">Long Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 2</td>
<td class="my-table-td">Long Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 3</td>
<td class="my-table-td">Lincolnshire</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 4</td>
<td class="my-table-td">Buffalo Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 5</td>
<td class="my-table-td">Kenilworth</td>
<td class="my-table-td">Not Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 6</td>
<td class="my-table-td">Schaumburg</td>
<td class="my-table-td">Not Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 7</td>
<td class="my-table-td">Schaumburg</td>
<td class="my-table-td">Not Logged In</td>
</tr>
</table>
So when you run that code snippet ^ what I want to see is 'helloWorld' centered above the 'Teachers, School, Status' row. I'm not sure why it only seems to be expanding a quarter of the table width - does it have to do with the table-layout: fixed style that I've set on the <table> element?
Link to JSFiddle
Two things:
1.) You need to add colspan="3" as an attribute to that thto make it span all three columns of that table.
2.) You should not use display: block for a table element, regardless if that's td, th, tr or whatever. The display setting of the th by default is table-cell- just leave that as it is, otherwise the table won't be a "real table" in the end (i.e. the cells loose their automatic way of aligning and adjusting themselves).
.my-card-table {
width: 100%;
border: 1px solid #D9D7D6;
table-layout: fixed!important;
}
.table-top-heading {
text-align: center;
}
.my-card-table-heading {
background-color: #E9E9E9!important;
font-family: "Proxima Nova Regular";
color: #000000;
font-size: 1rem;
padding: 10px 5px 10px 5px;
}
.my-card-table-heading-inner {
background-color: #E9E9E9!important;
font-family: "Proxima Nova Regular";
color: #000000;
font-size: 1rem;
text-align: left;
padding: 10px 0 10px 30px
}
.my-card-table-row-grey {
background-color: #F2F3F3!important;
padding: 10px!important;
}
.my-card-table-row-white {
background-color: #ffffff!important;
padding: 10px!important;
}
..my-table-td {
text-align: left;
padding-left: 30px;
}
.my-card-link {
color: #0e5b8b;
}
.my-card-link:hover {
font-family: "Proxima Nova Bold";
color: #0e5b8b;
}
.my-card-link-2 {
color: #212529;
}
<table class="my-card-table">
<tr class="table-top-heading">
<th class="table-top-heading-header" colspan="3">HelloWorld</th>
</tr>
<tr class="my-card-table-heading">
<th class="my-card-table-heading-inner">Teachers</th>
<th class="my-card-table-heading-inner">School</th>
<th class="my-card-table-heading-inner">Status</th>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 1</td>
<td class="my-table-td">Long Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 2</td>
<td class="my-table-td">Long Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 3</td>
<td class="my-table-td">Lincolnshire</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 4</td>
<td class="my-table-td">Buffalo Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 5</td>
<td class="my-table-td">Kenilworth</td>
<td class="my-table-td">Not Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 6</td>
<td class="my-table-td">Schaumburg</td>
<td class="my-table-td">Not Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 7</td>
<td class="my-table-td">Schaumburg</td>
<td class="my-table-td">Not Logged In</td>
</tr>
</table>
You can set your ".my-card-table" and ".table-top-heading" to {display:flex}, and your ".table-top-heading-header" to {width:100%; text-align: center}.
You also had an extra (.) on your (my-table-td ) class.
Here's a working solution ;)
.my-card-table {
width: 100%;
border: 1px solid #D9D7D6;
display: flex;
}
.table-top-heading {
width: 100%;
display: flex;
}
.table-top-heading-header {
width: 100%;
text-align: center;
}
.my-card-table-heading {
background-color: #E9E9E9!important;
font-family: "Proxima Nova Regular";
color: #000000;
font-size: 1rem;
padding: 10px 5px 10px 5px;
}
.my-card-table-heading-inner {
background-color: #E9E9E9!important;
font-family: "Proxima Nova Regular";
color: #000000;
font-size: 1rem;
text-align: left;
padding: 10px 30px
}
.my-card-table-row-grey {
background-color: #F2F3F3!important;
padding: 10px!important;
}
.my-card-table-row-white {
background-color: #ffffff!important;
padding: 10px!important;
}
.my-table-td {
text-align: left;
padding-left: 30px;
}
.my-card-link {
color: #0e5b8b;
}
.my-card-link:hover {
font-family: "Proxima Nova Bold";
color: #0e5b8b;
}
.my-card-link-2 {
color: #212529;
}
<table class="my-card-table">
<tr class="table-top-heading">
<th class="table-top-heading-header">HelloWorld</th>
</tr>
<tr class="my-card-table-heading">
<th class="my-card-table-heading-inner">Teachers</th>
<th class="my-card-table-heading-inner">School</th>
<th class="my-card-table-heading-inner">Status</th>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 1</td>
<td class="my-table-td">Long Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 2</td>
<td class="my-table-td">Long Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 3</td>
<td class="my-table-td">Lincolnshire</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 4</td>
<td class="my-table-td">Buffalo Grove</td>
<td class="my-table-td">Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 5</td>
<td class="my-table-td">Kenilworth</td>
<td class="my-table-td">Not Logged In</td>
</tr>
<tr class="my-card-table-row-white">
<td class="my-table-td">Teacher 6</td>
<td class="my-table-td">Schaumburg</td>
<td class="my-table-td">Not Logged In</td>
</tr>
<tr class="my-card-table-row-grey">
<td class="my-table-td">Teacher 7</td>
<td class="my-table-td">Schaumburg</td>
<td class="my-table-td">Not Logged In</td>
</tr>
</table>
I am working with HTML tables and need to achieve like attached image.
When I try to achieve this,I caught problem like this
① I couldn't figure out how not to display border line.
② Each cell size is not aligned compared to desired result.
I would like to achieve in a certain way. If you have any opinion, please let me know.
Thanks
table {
border-collapse:collapse;
table-layout: fixed;
text-align: center;
width: 10rem;
height: 10rem;}
td {
border:solid black 1px;
}
.noborder {
}
.noborder2{
}
<table>
<tbody>
<tr>
<td class="noborder">Total (summary)</td>
<td class="noborder"></td>
<td class="noborder"></td>
<td class="noborder"></td>
</tr>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
<td class="noborder2"></td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>6</td>
</tr>
</tbody>
</table>
You can do something like this using empty-cells: hide;.
Note: but the border is bit off since it removes the td border where the content doesn't exists. If that's ok.
.tbl {
empty-cells: hide;
border: 1px solid #999;
}
td {
background: #fff;
border: 1px solid #999;
padding: 10px 15px;
cursor: pointer;
}
<table class="tbl" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="noborder">Total (summary)</td>
<td class="noborder"></td>
<td class="noborder"></td>
<td class="noborder"></td>
</tr>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
<td class="noborder2"></td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>6</td>
</tr>
</tbody>
</table>
Here is the another version:
.MainDiv {
border: 1px solid #999;
display: inline-block;
}
table.tbl {
empty-cells: hide;
}
td.noborder {
background: #fff;
border: 1px solid #999;
width: 50px;
height: 50px;
text-align: center;
}
td.removeBorder {
width: 100px;
height: 50px;
}
td:empty {
visibility: hidden;
}
<div class="MainDiv">
<table class="tbl" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="3" class="removeBorder">Total (summary)</td>
</tr>
<tr>
<td class="noborder">A</td>
<td class="noborder">B</td>
<td class="noborder">C</td>
<td class="noborder"></td>
</tr>
<tr>
<td class="noborder">1</td>
<td class="noborder">2</td>
<td class="noborder">3</td>
<td class="noborder">6</td>
</tr>
</tbody>
</table>
</div>
How to make the horizontal scroll bar only affects the gray columns in the following illustration.
html,
body {
background: #ccc;
font-family: Arial, sans-serif
}
#table {
background: white;
margin: 100px auto;
width: 400px;
overflow: auto;
text-align: center;
}
#inner-table {
border-collapse: collapse;
border-radius: 3px;
overflow: hidden
}
td,
th {
padding: 5px 10px;
}
th {
border-bottom: 1px solid #B8C2CC
}
.sticky {
background-color: #1C3D5A;
color: #dae1e7;
}
.scroll {
background-color: #B8C2CC;
color: #22292f
}
<div id="table">
<table id="inner-table">
<thead>
<tr>
<th class="sticky">sticky</th>
<th class="sticky">sticky</th>
<th class="scroll">scroll</th>
<th class="scroll">scroll</th>
<th class="scroll">scroll</th>
<th class="scroll">scroll</th>
<th class="scroll">scroll</th>
<th class="scroll">scroll</th>
<th class="sticky">sticky</th>
<th class="sticky">sticky</th>
</tr>
</thead>
<tbody>
<tr>
<td class="sticky">1</td>
<td class="sticky">2</td>
<td class="scroll">3</td>
<td class="scroll">4</td>
<td class="scroll">5</td>
<td class="scroll">6</td>
<td class="scroll">7</td>
<td class="scroll">8</td>
<td class="sticky">9</td>
<td class="sticky">10</td>
</tr>
<tr>
<td class="sticky">11</td>
<td class="sticky">12</td>
<td class="scroll">13</td>
<td class="scroll">14</td>
<td class="scroll">15</td>
<td class="scroll">16</td>
<td class="scroll">17</td>
<td class="scroll">18</td>
<td class="sticky">19</td>
<td class="sticky">20</td>
</tr>
</tbody>
</table>
</div>
This was rather more difficult to put together than I anticipated - and even now, I am wondering if there isn't a much simpler approach.
The approach below utilises:
an outer container which contains two position: absolute tables
a fixed-width inner container - using margins for positioning inside the outer container - with a scrollbar, which allows you to see the oversized table it contains
Working Example:
html,
body {
background: #ccc;
font-family: Arial, sans-serif
}
.outer-container {
position: relative;
background-color: white;
margin: 40px auto;
width: 400px;
overflow: hidden;
text-align: center;
}
.outer-container,
.inner-container {
height: 125px;
}
table {
height: 108px;
}
.inner-container table {
border-radius: 3px;
}
td, th {
padding: 5px 10px;
}
th {
border-bottom: 1px solid #B8C2CC
}
.fixed-table th,
.fixed-table td {
background-color: #1C3D5A;
color: #dae1e7;
}
.inner-container {
margin: 0 130px;
max-width: 612px;
overflow: auto;
}
.inner-container > table {
background-color: #B8C2CC;
color: #22292f
}
.outer-container > table {
position: absolute;
top: 0;
border-collapse: collapse;
}
.outer-container > table:nth-of-type(1) {
left: 0;
}
.outer-container > table:nth-of-type(2) {
right: 0;
}
<div class="outer-container">
<table class="fixed-table">
<thead>
<tr>
<th>sticky</th>
<th>sticky</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>11</td>
<td>12</td>
</tr>
</tbody>
</table>
<div class="inner-container">
<table>
<thead>
<tr>
<th>scroll</th>
<th>scroll</th>
<th>scroll</th>
<th>scroll</th>
<th>scroll</th>
<th>scroll</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
</tr>
</tbody>
</table>
</div>
<table class="fixed-table">
<thead>
<tr>
<th>sticky</th>
<th>sticky</th>
</tr>
</thead>
<tbody>
<tr>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td>19</td>
<td>20</td>
</tr>
</tbody>
</table>
</div>
CSS3 should do the job.
table {
position: relative;
padding-left: (width-of-your-td-elements);
}
table td:first-of-type {
position: absolute;
left: 0;
}
Sources
I'm trying to make my table contents scrollable, I've had to create a table inside one of the table rows which means if the table has more than one row the contents isn't aligned with the correct heading as showing in the fiddle;
https://jsfiddle.net/f5ax5w2r/
thead.panel-heading {
background-color: #242a30;
border-color: #242a30;
border-bottom: 1px solid #242a30;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
cursor: move;
width: 100%;
}
thead.panel-heading tr th {
color: #ffffff;
font-weight: 500;
padding: 10px 40px !important;
text-align: left;
}
tbody.panel-content {
background-color: #f0f3f4;
}
tbody.panel-content tr td {
padding: 10px 20px !important;
text-align: left;
}
tbody div {
overflow-x: hidden;
overflow-y: scroll;
height: 300px;
}
<table>
<thead class="panel-heading">
<tr>
<th>Client</th>
<th>Client</th>
</tr>
</thead>
<tbody class="panel-content">
<tr>
<td>
<div class="scrollit">
<table>
<tr>
<td>Alex Best</td>
<td>Yahoo Answers</td>
</tr>
<tr>
<td>Andrew Smith</td>
<td>Monkey Tube</td>
</tr>
<tr>
<td>James Harris</td>
<td>Limewire</td>
</tr>
<tr>
<td>Mike Anderson</td>
<td>Twitter</td>
</tr>
</table>
</div>
</td>
</tr>
</tbody>
</table>
The number of table cells do not match in each table row in your code. Adding the correct colspan value should do it.
thead.panel-heading {
background-color: #242a30;
border-color: #242a30;
border-bottom: 1px solid #242a30;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
cursor: move;
width: 100%;
}
thead.panel-heading tr th {
color: #ffffff;
font-weight: 500;
padding: 10px 40px !important;
text-align: left;
}
tbody.panel-content {
background-color: #f0f3f4;
}
tbody.panel-content tr td {
padding: 10px 20px !important;
text-align: left;
}
tbody div {
overflow-x: hidden;
overflow-y: scroll;
height: 300px;
}
<table>
<thead class="panel-heading">
<tr>
<th>Client</th>
<th>Client</th>
</tr>
</thead>
<tbody class="panel-content">
<tr>
<td colspan="2">
<div class="scrollit">
<table>
<tr>
<td>Alex Best</td>
<td>Yahoo Answers</td>
</tr>
<tr>
<td>Andrew Smith</td>
<td>Monkey Tube</td>
</tr>
<tr>
<td>James Harris</td>
<td>Limewire</td>
</tr>
<tr>
<td>Mike Anderson</td>
<td>Twitter</td>
</tr>
</table>
</div>
</td>
</tr>
</tbody>
</table>
Try adding colspan="2" to the td which has table inside.
https://jsfiddle.net/f5ax5w2r/
<table>
<thead class="panel-heading">
<tr>
<th>Client</th>
<th>Client</th>
</tr>
</thead>
<tbody class="panel-content">
<tr>
<td colspan="2">
<div class="scrollit">
<table>
<tr>
<td>Alex Best</td>
<td>Yahoo Answers</td>
</tr>
<tr>
<td>Andrew Smith</td>
<td>Monkey Tube</td>
</tr>
<tr>
<td>James Harris</td>
<td>Limewire</td>
</tr>
<tr>
<td>Mike Anderson</td>
<td>Twitter</td>
</tr>
</table>
</div>
</td>
</tr>
</tbody>
</table>