i have a outer table with a fixed row height (in this example 24px).
i want to nest a table to add some content but also want to mimic the row heights and borders inside.
But there is a 1px difference as you can see here:
I cannot explain this, but have the feeling that is has something to do with the rowspan and maybe the nested table with flexboxes.
Question:
I wonder that the innerTable has a expected height of 72px, but the parent td.itemblock has a height of 72.8px.
Can someone tell me the reason for this difference? And is there some setting to prevent this?
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
border-spacing: 0;
}
tr {
height: 24px;
}
td {
border-bottom: 1px solid black;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}
.firstColumn {
width: 24px;
border-right: 1px solid black;
}
td.small {
width: 12px;
border-right: 1px solid black;
}
.title {
flex-grow: 1;
display: block;
text-overflow: ellipsis;
overflow: hidden;
height: 24px;
}
.item {
display: flex;
background-color: lightblue;
padding-left: 4px;
padding-right: 4px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 1px;
height: 100%;
}
.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
}
.itemCell {
position: relative;
}
.innerTable td.blockCell {
border-bottom: 1px solid black;
}
<html>
<head>
</head>
<body>
<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">
<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
</table>
</body>
<html>
Update:
Its confirmed to happen in Mac Chrome and Safari, probably also in other browsers (check the result with Run Code Snippet)
it happens regardless if the browser zoom in/out is used or not.
With the proposals i was able to assemble this, which looks like it is working. The changes are:
use box-shadows instead of border-bottom
set inner table height
set height of Item div to calc(100% - 0.75px)
Though it seems i have a "hacky" solution, still i dont have an explanation for this! Any html table experts?
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
border-spacing: 0;
}
tr {
height: 24px;
}
td {
box-shadow: 3px -3.5px 0px -3px rgba(0, 0, 0, 1) inset;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}
.firstColumn {
width: 24px;
border-right: 1px solid black;
}
td.small {
width: 12px;
border-right: 1px solid black;
}
.title {
display: block;
text-overflow: ellipsis;
overflow: hidden;
}
.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
height: 72px;
}
.itemCell {}
.item {
height: calc(100% - 0.75px);
background: lightblue;
display: flex;
background-color: lightblue;
padding-left: 4px;
padding-right: 4px;
}
.innerTable td.blockCell {
box-shadow: 3px -3.5px 0px -3px rgba(0, 0, 0, 1) inset;
}
<html>
<head>
</head>
<body>
<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">
<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
</table>
</body>
<html>
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
}
tr {
height: 24px;
}
td {
box-shadow: 3px -3.5px 0px -3px rgba(0,0,0,1) inset;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}
.firstColumn {
width: 24px;
border-right: 1px solid black;
}
td.small {
width: 12px;
border-right: 1px solid black;
}
.title {
flex-grow: 1;
display: block;
text-overflow: ellipsis;
overflow: hidden;
height: 24px;
}
.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
}
td.itemCell {
background: lightblue;
}
.itemCell {
position: relative;
}
.innerTable td.blockCell {
box-shadow: 3px -3.5px 0px -3px rgba(0,0,0,1) inset;
}
<html>
<head>
</head>
<body>
<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">
<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
</table>
</body>
<html>
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
}
tr {
height: 24px;
}
td {
box-shadow: 3px -3.5px 0px -3px rgba(0,0,0,1) inset;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}
.firstColumn {
width: 24px;
border-right: 1px solid black;
}
td.small {
width: 12px;
border-right: 1px solid black;
}
.title {
flex-grow: 1;
display: block;
text-overflow: ellipsis;
overflow: hidden;
height: 24px;
}
.item {
display: flex;
background-color: lightblue;
padding-left: 4px;
padding-right: 4px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 1px;
}
.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
}
.itemCell {
position: relative;
}
.innerTable td.blockCell {
box-shadow: 3px -3.5px 0px -3px rgba(0,0,0,1) inset;
}
<html>
<head>
</head>
<body>
<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">
<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
</table>
</body>
<html>
1. Cause
Using box-sizing:border-box is relevant only for the parent cell who has the border - but the nested table doesn't care about it's parent's border, only about its own.
In a plain table the border of the cells is part of the cell and thus considered in the computation of the cell heights:
<tr>
<td></td>
<td></td>
</tr>
In the case of a nested table, the border belongs to the cell that contains the table, and thus is not available for computing the height of the cell:
<tr>
<td rowspan="2">
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>
</td>
</tr>
2. Solution
Finding the solution is harder than determining the cause.
My idea is to
.innerTable{
use the margin to stretch the inner table to cover the border of the containing cell:
margin-top: -1px;
margin-bottom: -1px;
then draw the border on the inner table so it looks again like the containing cell had a border:
border-top: 1px solid black;
border-bottom: 1px solid black;
}
Setting only margin-bottom (or even worse, setting margin-bottom:-2px) doesn't help - border-collapse: collapse; means that two cells share their border, but it doesn't change that they end up having borders on both sides, so the size of both borders needs to be counted.
.innerTable{
margin-top: -1px;
margin-bottom: -1px;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
border-spacing: 0;
}
tr {
height: 24px;
}
td {
border-bottom: 1px solid black;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}
.firstColumn {
width: 24px;
border-right: 1px solid black;
}
td.small {
width: 12px;
border-right: 1px solid black;
}
.title {
flex-grow: 1;
display: block;
text-overflow: ellipsis;
overflow: hidden;
height: 24px;
}
.item {
display: flex;
background-color: lightblue;
padding-left: 4px;
padding-right: 4px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 1px;
height: 100%;
}
.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
}
.itemCell {
position: relative;
}
.innerTable td.blockCell {
border-bottom: 1px solid black;
}
<html>
<head>
</head>
<body>
<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">
<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
</table>
</body>
<html>
As I have already mentioned as a comment, first of all ensure that the browser isn't zoomed-in so that you have accurate results.
If you carefully notice the rows where all cells are single, you see that each table cell has a total height of 24px - 23px of the cell plus 1px of the the border.
The table cells next to the table-block, have a height of 24.333px, this is due to the fact that there are 2px missing from the borders.
So, the total height of the cell that holds the table item should be 24*3=72px+1px border, giving a total of 73px. Now divide this by 3 (the rowspan) and you can see that each table cell next to the merged one equal to 24.333px (73/3). This is simply the outcome of the observation.
The thing with tables it that they sometimes render in an arbitrary way, so you can't really predict the rendered result. I am sure there is a way to prevent it, in this particular example I would set margin-bottom:-1px to the table.innertable.
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
}
tr {
height: 24px;
}
td {
border-bottom: 1px solid black;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}
.firstColumn {
width: 24px;
border-right: 1px solid black;
}
td.small {
width: 12px;
border-right: 1px solid black;
}
.title {
flex-grow: 1;
display: block;
text-overflow: ellipsis;
overflow: hidden;
height: 24px;
}
.item {
display: flex;
background-color: lightblue;
padding-left: 4px;
padding-right: 4px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 1px;
height: 100%;
}
.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
}
.itemCell {
position: relative;
}
.innerTable td.blockCell {
border-bottom: 1px solid black;
}
table.innerTable {
margin-bottom:-1px;
}
<html>
<head>
</head>
<body>
<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">
<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
</table>
</body>
</html>
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>
I have a table with a sticky column (see jsfiddle below). But I´m trying to have a vertical scroll just on the table body so the headers are always visible and the height of tbody should be fixed. How can I do this?
body {
font: 16px Calibri;
}
table {
border-collapse: separate;
border-top: 3px solid grey;
}
td,th {
margin: 0;
border: 3px solid grey;
border-top-width: 0px;
white-space: nowrap;
}
div {
width: 600px;
overflow-x: scroll;
margin-left: 5em;
overflow-y: visible;
padding-bottom: 1px;
}
.headcol {
position: absolute;
width: 5em;
left: 0;
top: auto;
border-right: 0px none black;
border-top-width: 3px;
/*only relevant for first row*/
margin-top: -3px;
/*compensate for top border*/
}
.long {
background: yellow;
letter-spacing: 1em;
}
<div>
<table>
<thead>
<tr>
<th class="headcol">sticky col</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead>
<tbody>
<tr>
<td class="headcol">1</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">2</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">3</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">4</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">5</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">6</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">7</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">8</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">9</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</tbody>
</table>
</div>
The end result should be similar to this:
http://demos.telerik.com/kendo-ui/grid/frozen-columns
You will need to set the position to fixed of the cell that you would like to remain fixed during vertical scroll.
.headcol {
position:fixed;
}
I'm quite inexperienced in all of this, but here's my problem. The columns in my table are being distributed weirdly. I'm doing this using Squarespace (don't judge), but I can edit the CSS and insert costume code. For some reason the first column is taking up a lot more space than the rest.
Here's what I've done:
.mytable {
border: 0px solid #009688;
width: 100%;
background-color: white;
white-space: nowrap;
overflow-x: auto;
display: block;
th {
padding: 4px;
text-align: left;
height:50px;
color: #eeeeee;
background-color: #009688;
}
td {
padding: 5px;
vertical-align: top;
border:0px;
line-height: 1.5em;
width: 100%;
}
tr:nth-child(odd) {
background-color: #E0F2F1
}
tr:nth-child(even) {
background-color: #fcfcfc
}
tr:hover {
background-color: #1DE9B6
}
}
<table class="mytable">
<tr>
<th>Menge</th>
<th>Bezeichnung</th>
</tr>
<tr>
<td>100 g</td>
<td>Geräucherter Lachs</td>
</tr>
<tr>
<td>2 Stück</td>
<td>Avocados</td>
</tr>
<tr>
<td>2 EL</td>
<td>Zitronensaft</td>
</tr>
<tr>
<td>½ Stück</td>
<td>Salatgurke</td>
</tr>
<tr>
<td>4 Stück</td>
<td>Eier</td>
</tr>
<tr>
<td>2 EL</td>
<td>Sesam</td>
</tr>
<tr>
<td>500 g</td>
<td>Sushireis</td>
</tr>
<tr>
<td>1 EL</td>
<td>Zucker</td>
</tr>
<tr>
<td>1 EL</td>
<td>Salz</td>
</tr>
<tr>
<td>4 EL</td>
<td>Reisessig</td>
</tr>
<tr>
<td>10 Stück</td>
<td>Noriblätter</td>
</tr>
<tr>
<td>1 Stück</td>
<td>Bambusmatte</td>
</tr>
</table>
Any suggestions? I should also add that I want the tables to be as responsive as possible (that's why I started playing with the CSS). Thanks!
.mytable {
border: 0px solid #009688;
background-color: white;
white-space: nowrap;
overflow-x: auto;
table-layout: fixed;
max-width: 600px;
width: 100%;
}
th {
padding: 10px;
text-align: left;
height:50px;
color: #eeeeee;
background-color: #009688;
width: 50%;
}
td {
padding: 10px;
vertical-align: top;
border:0px;
line-height: 1.5em;
width: 50%;
}
tr:nth-child(odd) {
background-color: #E0F2F1
}
tr:nth-child(even) {
background-color: #fcfcfc
}
tr:hover {
background-color: #1DE9B6
}
<table class="mytable">
<tr>
<th>Menge</th>
<th>Bezeichnung</th>
</tr>
<tr>
<td>100 g</td>
<td>Geräucherter Lachs</td>
</tr>
<tr>
<td>2 Stück</td>
<td>Avocados</td>
</tr>
<tr>
<td>2 EL</td>
<td>Zitronensaft</td>
</tr>
<tr>
<td>½ Stück</td>
<td>Salatgurke</td>
</tr>
<tr>
<td>4 Stück</td>
<td>Eier</td>
</tr>
<tr>
<td>2 EL</td>
<td>Sesam</td>
</tr>
<tr>
<td>500 g</td>
<td>Sushireis</td>
</tr>
<tr>
<td>1 EL</td>
<td>Zucker</td>
</tr>
<tr>
<td>1 EL</td>
<td>Salz</td>
</tr>
<tr>
<td>4 EL</td>
<td>Reisessig</td>
</tr>
<tr>
<td>10 Stück</td>
<td>Noriblätter</td>
</tr>
<tr>
<td>1 Stück</td>
<td>Bambusmatte</td>
</tr>
</table>
I am able to add the scrollbar, but the problem I am facing is that when the header is too big, the header overflows and is not breaking down. I want the header text to break down to next line and the rest of the columns should take the same height as the header.
HTML:
<div id="outerdiv">
<div id="innerdiv">
<table>
<tr>
<td class="headcol">Big Rowwwww1</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">2</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">3</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">4</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">5</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">6</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">7</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">8</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">9</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</table>
</div>
</div>
CSS:
body {
font:16px Calibri;
}
table {
border-collapse:separate;
border-top: 3px solid grey;
}
td {
margin:0;
border:3px solid grey;
border-top-width:0px;
white-space:nowrap;
}
#outerdiv {
position: absolute;
top: 0;
left: 0;
right: 5em;
}
#innerdiv {
width: 100%;
overflow-x:scroll;
margin-left: 5em;
overflow-y:visible;
padding-bottom:1px;
}
.headcol {
position:absolute;
width:5em;
left:0;
top:auto;
border-right: 0px none black;
border-top-width:3px;
/*only relevant for first row*/
margin-top:-3px;
/*compensate for top border*/
}
.headcol:before {
content:'Row ';
}
.long {
background:yellow;
letter-spacing:1em;
}
The current working code is below in the fiddle link
http://jsfiddle.net/DYgD6/693/
body {
font: 16 px Calibri;
}
table {
border - collapse: separate;
border - top: 3 px solid grey;
}
td {
margin: 0;
border: 3 px solid grey;
border - top - width: 0 px;
/*white-space:nowrap;*/
height: 80 px;
}#
outerdiv {
position: absolute;
top: 0;
left: 0;
right: 5e m;
}#
innerdiv {
width: 100 % ;
overflow - x: scroll;
margin - left: 5e m;
overflow - y: visible;
padding - bottom: 1 px;
}
.headcol {
position: absolute;
width: 5e m;
left: 0;
top: auto;
border - right: 0 px none black;
border - top - width: 3 px;
/*only relevant for first row*/
margin - top: -3 px;
/*compensate for top border*/
word - wrap: break -word;
}
.headcol: before {
content: 'Row ';
}
.long {
background: yellow;
letter - spacing: 1e m;
}
<div id="outerdiv">
<div id="innerdiv">
<table>
<tr>
<td class="headcol">Big Rowwwww1</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">2</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">3</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">4</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">5</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">6</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">7</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">8</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">9</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</table>
</div>
</div>
I have done few changes in your existing css, please look into the same and try this:
body {
font:16px Calibri;
}
table {
border-collapse:separate;
border-top: 3px solid grey;
}
td {
margin:0;
border:3px solid grey;
border-top-width:0px;
/*white-space:nowrap;*/
height:80px;
}
#outerdiv {
position: absolute;
top: 0;
left: 0;
right: 5em;
}
#innerdiv {
width: 100%;
overflow-x:scroll;
margin-left: 5em;
overflow-y:visible;
padding-bottom:1px;
}
.headcol {
position:absolute;
width:5em;
left:0;
top:auto;
border-right: 0px none black;
border-top-width:3px;
/*only relevant for first row*/
margin-top:-3px;
/*compensate for top border*/
word-wrap: break-word;
}
.headcol:before {
content:'Row ';
}
.long {
background:yellow;
letter-spacing:1em;
}