Reposonsive table with headers and Y scroll [duplicate] - css

This question already has answers here:
How to set tbody height with overflow scroll
(16 answers)
Closed 5 years ago.
I'm stuck on a table design.
My headers aren't lining up with my body tds, and my scroll is throwing off alignment.
I imagine I could just use a
table-header-group
However, that loses my scroll.
If I put it an a div, then I lose my header to the scroll.
Attached is a fiddle for viewing.
Anyways, How can I:
1. Align my head with the body
2. use scroll in the Y
3. Fit the data using as a responsive table
First, Fiddle with weird CSS "display:" usage
Fiddle
Updated Fiddle height of 80px overridden:
https://jsfiddle.net/t1zss67n/4/

Your display reset could be on every tr, then adding a padding to thead of equal average width of the scrollbar should do. https://jsfiddle.net/t1zss67n/5/
actually very similar to How to set tbody height with overflow scroll
thead {
display:block;
padding-right:17px ;
}
thead tr, tbody tr {
display:table;
width:100%;
table-layout:fixed;
}
.thead {
background-clip: padding-box;
background-color: #f5f5f5;
background-image: linear-gradient(to bottom,#fafafa 0,#ededed 100%);
background-repeat: repeat-x;
font-weight: 700;
font-size: 12px;
}
table ,tr td{
border:1px solid red
}
tbody {
max-height: 800px;
}
tbody {
display:block;
overflow-y:scroll;
}
thead {
display:block;
padding-right:17px ;
}
thead tr, tbody tr {
display:table;
width:100%;
table-layout:fixed;
}
tr td:first-child {
width: 60px;
}
.table-hover>tbody>tr:hover> td{
background-color: #ffa;
border-bottom-color: #ffa;
}
.table-hover>tbody>tr>td:hover:not(:first-child) {
background-color: #fff;
border: 1px solid #aaa;
}
td {
text-overflow: ellipsis;
width: 10px;
white-space: nowrap;
overflow: hidden;
padding: 2px;
}
<table class="table table-hover table-responsive">
<thead>
<tr class="thead">
<td>Name</td>
<td>Nov16</td>
<td>Dec16</td>
<td>Jan17</td>
<td>Feb17</td>
<td>Mar17</td>
<td>Apr17</td>
<td>May17</td>
<td>Jun17</td>
<td>Jul17</td>
<td>Aug17</td>
<td>Sept17</td>
<td>Oct17</td>
<td>RTM</td>
<td >2012</td>
<td>2013</td>
<td>2014</td>
<td>2015</td>
<td>2016</td>
<td>YTD</td>
</tr>
</thead>
<tbody>
<tr role="row">
<td class="text-left">Gabe Maloney</td>
<td class="text-right">253</td>
<td class="text-right">229</td>
<td class="text-right">78</td>
<td class="text-right">36</td>
<td class="text-right">236</td>
<td class="text-right">107</td>
<td class="text-right">106</td>
<td class="text-right">246</td>
<td class="text-right">66</td>
<td class="text-right">71</td>
<td class="text-right">172</td>
<td class="text-right">235</td>
<td class="text-right ttm">1728</td>
<td class="text-right">1943</td>
<td class="text-right">1275</td>
<td class="text-right">1810</td>
<td class="text-right">225</td>
<td class="text-right">985</td>
<td class="text-right ytd">896</td>
</tr>
<tr role="row">
<td class="text-left">Adrien Johnson</td>
<td class="text-right">274</td>
<td class="text-right">291</td>
<td class="text-right">195</td>
<td class="text-right">133</td>
<td class="text-right">171</td>
<td class="text-right">19</td>
<td class="text-right">79</td>
<td class="text-right">31</td>
<td class="text-right">262</td>
<td class="text-right">208</td>
<td class="text-right">58</td>
<td class="text-right">117</td>
<td class="text-right ttm">1819</td>
<td class="text-right">1799</td>
<td class="text-right">1010</td>
<td class="text-right">336</td>
<td class="text-right">417</td>
<td class="text-right">1803</td>
<td class="text-right ytd">755</td>
</tr>
<tr role="row">
<td class="text-left">Axel Johnson</td>
<td class="text-right">275</td>
<td class="text-right">294</td>
<td class="text-right">232</td>
<td class="text-right">80</td>
<td class="text-right">128</td>
<td class="text-right">143</td>
<td class="text-right">255</td>
<td class="text-right">235</td>
<td class="text-right">186</td>
<td class="text-right">48</td>
<td class="text-right">97</td>
<td class="text-right">199</td>
<td class="text-right ttm">2029</td>
<td class="text-right">1031</td>
<td class="text-right">787</td>
<td class="text-right">333</td>
<td class="text-right">1259</td>
<td class="text-right">1261</td>
<td class="text-right ytd">1020</td>
</tr>
<tr role="row">
<td class="text-left">George Johnson</td>
<td class="text-right">39</td>
<td class="text-right">102</td>
<td class="text-right">127</td>
<td class="text-right">171</td>
<td class="text-right">128</td>
<td class="text-right">283</td>
<td class="text-right">201</td>
<td class="text-right">231</td>
<td class="text-right">34</td>
<td class="text-right">150</td>
<td class="text-right">76</td>
<td class="text-right">80</td>
<td class="text-right ttm">1339</td>
<td class="text-right">907</td>
<td class="text-right">1221</td>
<td class="text-right">1876</td>
<td class="text-right">999</td>
<td class="text-right">2012</td>
<td class="text-right ytd">772</td>
</tr>
<tr role="row">
<td class="text-left">Reek Jones</td>
<td class="text-right">224</td>
<td class="text-right">109</td>
<td class="text-right">162</td>
<td class="text-right">192</td>
<td class="text-right">226</td>
<td class="text-right">270</td>
<td class="text-right">257</td>
<td class="text-right">65</td>
<td class="text-right">137</td>
<td class="text-right">172</td>
<td class="text-right">168</td>
<td class="text-right">173</td>
<td class="text-right ttm">1885</td>
<td class="text-right">1086</td>
<td class="text-right">649</td>
<td class="text-right">447</td>
<td class="text-right">480</td>
<td class="text-right">825</td>
<td class="text-right ytd">972</td>
</tr>
<tr role="row">
<td class="text-left">JP Lefkort</td>
<td class="text-right">76</td>
<td class="text-right">82</td>
<td class="text-right">18</td>
<td class="text-right">54</td>
<td class="text-right">27</td>
<td class="text-right">240</td>
<td class="text-right">50</td>
<td class="text-right">248</td>
<td class="text-right">197</td>
<td class="text-right">294</td>
<td class="text-right">20</td>
<td class="text-right">262</td>
<td class="text-right ttm">1328</td>
<td class="text-right">2007</td>
<td class="text-right">143</td>
<td class="text-right">1126</td>
<td class="text-right">803</td>
<td class="text-right">1771</td>
<td class="text-right ytd">1071</td>
</tr>
<tr role="row">
<td class="text-left">Susan Segal</td>
<td class="text-right">101</td>
<td class="text-right">236</td>
<td class="text-right">95</td>
<td class="text-right">204</td>
<td class="text-right">213</td>
<td class="text-right">197</td>
<td class="text-right">292</td>
<td class="text-right">49</td>
<td class="text-right">44</td>
<td class="text-right">75</td>
<td class="text-right">137</td>
<td class="text-right">49</td>
<td class="text-right ttm">1495</td>
<td class="text-right">1215</td>
<td class="text-right">1667</td>
<td class="text-right">546</td>
<td class="text-right">753</td>
<td class="text-right">849</td>
<td class="text-right ytd">646</td>
</tr>
<tr role="row">
<td class="text-left">Antonio Townsend</td>
<td class="text-right">244</td>
<td class="text-right">198</td>
<td class="text-right">98</td>
<td class="text-right">262</td>
<td class="text-right">281</td>
<td class="text-right">141</td>
<td class="text-right">219</td>
<td class="text-right">273</td>
<td class="text-right">123</td>
<td class="text-right">68</td>
<td class="text-right">15</td>
<td class="text-right">114</td>
<td class="text-right ttm">1895</td>
<td class="text-right">143</td>
<td class="text-right">1612</td>
<td class="text-right">1564</td>
<td class="text-right">148</td>
<td class="text-right">1042</td>
<td class="text-right ytd">812</td>
</tr>
</tbody>
</table>

Answered: Do not scroll table headings when scrolling down a html table
See specifically:
http://www.imaputz.com/cssStuff/bigFourVersion.html
This fiddle may provide the best solution though
jsfiddle.net/deborah/Msvvr/

Related

align-self: flex-end won't move the game board to the bottom of the page?

Hey friends I'm making a connect 4 game. I'm using a table for the board. I'm also using flexbox to position the board. I have the body set to flex, and used justify-content to center it horizontally and I thought align-items: flex-end would put it at the bottom of the page, but it's not working? Any help would be greatly appreciated:)
html, body {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: flex-end;
}
table {
margin: auto;
background-color: blue;
}
td {
border: 1px solid red;
width: 100px;
height: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Connect Four</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="board-wrapper">
<table>
<tr class="row-1">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-2">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-3">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-4">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-5">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-6">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
</table>
</div>
</body>
</html>
The board actually is at the bottom. You just need the parent to be at least the height of the viewport using min-height: 100vh.
html, body {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: flex-end;
min-height: 100vh;
}
table {
margin: auto;
background-color: blue;
}
td {
border: 1px solid red;
width: 100px;
height: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Connect Four</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="board-wrapper">
<table>
<tr class="row-1">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-2">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-3">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-4">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-5">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
<tr class="row-6">
<td class="column-1"></td>
<td class="column-2"></td>
<td class="column-3"></td>
<td class="column-4"></td>
<td class="column-5"></td>
<td class="column-6"></td>
<td class="column-7"></td>
</tr>
</table>
</div>
</body>
</html>
The table is being aligned to the bottom, but the body's height is not the viewport height. Add a height: 100vh to the body and you'll see it.

CSS vertical-align, how can I remove the little spacing below the text?

I have this code. Despite of being inside a td, and having specified this CSS:
.day {
text-align: right;
padding: 5px;
vertical-align: middle;
border: 1px solid black;
}
.day--hole {
color: lightgray;
}
.day--today {
background: pink;
}
<table>
<tbody>
<tr>
<td class="day day--hole">30</td>
<td class="day day--hole">31</td>
<td class="day">1</td>
<td class="day">2</td>
<td class="day">3</td>
<td class="day">4</td>
<td class="day">5</td>
</tr>
<tr>
<td class="day">6</td>
<td class="day">7</td>
<td class="day">8</td>
<td class="day">9</td>
<td class="day">10</td>
<td class="day">11</td>
<td class="day">12</td>
</tr>
<tr>
<td class="day">13</td>
<td class="day">14</td>
<td class="day">15</td>
<td class="day">16</td>
<td class="day">17</td>
<td class="day">18</td>
<td class="day">19</td>
</tr>
<tr>
<td class="day">20</td>
<td class="day day--today">21</td>
<td class="day">22</td>
<td class="day">23</td>
<td class="day">24</td>
<td class="day">25</td>
<td class="day">26</td>
</tr>
<tr>
<td class="day">27</td>
<td class="day">28</td>
<td class="day">29</td>
<td class="day">30</td>
<td class="day">31</td>
<td class="day day--hole">1</td>
<td class="day day--hole">2</td>
</tr>
</tbody>
</table>
There's a visible gap between the position where the text should be centered and the current position of the text. It looks "upper" than it should and not totally centered. Why does this happen and how can I solve it without recurring to change the HTML or use flexbox?
That's because these numbers technically are text, and text - when using letters - has letters like g, j, p etc. which extend below the baseline. That's part of the line-height, and the vertical centering centers that line-height, regardless if there are letters like g, j, p in the text or not. So it looks a bit vertically offset as you describe it.
To compensate that, you could apply a vertical offset, as I did it in the first and last row of this snippet, using a wrapper for the numbers and applying position: relative and transform: translateY(1px); (or any value you like) to it:
.day {
text-align: right;
padding: 5px;
vertical-align: middle;
border: 1px solid black;
}
.day--hole {
color: lightgray;
}
.day--today {
background: pink;
}
.offset {
position: relative;
transform: translateY(1px);
}
<table>
<tbody>
<tr>
<td class="day day--hole"><div class="offset">30</div></td>
<td class="day day--hole"><div class="offset">31</div></td>
<td class="day"><div class="offset">1</div></td>
<td class="day"><div class="offset">2</div></td>
<td class="day"><div class="offset">3</div></td>
<td class="day"><div class="offset">4</div></td>
<td class="day"><div class="offset">5</div></td>
</tr>
<tr>
<td class="day">6</td>
<td class="day">7</td>
<td class="day">8</td>
<td class="day">9</td>
<td class="day">10</td>
<td class="day">11</td>
<td class="day">12</td>
</tr>
<tr>
<td class="day">13</td>
<td class="day">14</td>
<td class="day">15</td>
<td class="day">16</td>
<td class="day">17</td>
<td class="day">18</td>
<td class="day">19</td>
</tr>
<tr>
<td class="day">20</td>
<td class="day day--today">21</td>
<td class="day">22</td>
<td class="day">23</td>
<td class="day">24</td>
<td class="day">25</td>
<td class="day">26</td>
</tr>
<tr>
<td class="day"><div class="offset">27</div></td>
<td class="day"><div class="offset">28</div></td>
<td class="day"><div class="offset">29</div></td>
<td class="day"><div class="offset">30</div></td>
<td class="day"><div class="offset">31</div></td>
<td class="day day--hole"><div class="offset">1</div></td>
<td class="day day--hole"><div class="offset">2</div></td>
</tr>
</tbody>
</table>
As an example I made the height higher than needed. But give the example below a try. The height and line-height should be equal to center the text.
let height = document.getElementById('height');
let days = Array.from( document.querySelectorAll('.day') );
height.addEventListener('input', () => {
days.forEach( day => {
day.style.setProperty( '--height', `${height.value}px` );
});
});
.day {
text-align: right;
padding: 5px;
height: var(--height);
line-height: var(--height);
border: 1px solid black;
}
.day--hole {
color: lightgray;
}
.day--today {
background: pink;
}
:root {
--height: 40px;
}
<form>
<label for="height">Height (play with it to say that the text remains centered)</label>
<input type="number" id="height" min="1" value="40">
</form>
<table>
<tbody>
<tr>
<td class="day day--hole">30</td>
<td class="day day--hole">31</td>
<td class="day">1</td>
<td class="day">2</td>
<td class="day">3</td>
<td class="day">4</td>
<td class="day">5</td>
</tr>
<tr>
<td class="day">6</td>
<td class="day">7</td>
<td class="day">8</td>
<td class="day">9</td>
<td class="day">10</td>
<td class="day">11</td>
<td class="day">12</td>
</tr>
<tr>
<td class="day">13</td>
<td class="day">14</td>
<td class="day">15</td>
<td class="day">16</td>
<td class="day">17</td>
<td class="day">18</td>
<td class="day">19</td>
</tr>
<tr>
<td class="day">20</td>
<td class="day day--today">21</td>
<td class="day">22</td>
<td class="day">23</td>
<td class="day">24</td>
<td class="day">25</td>
<td class="day">26</td>
</tr>
<tr>
<td class="day">27</td>
<td class="day">28</td>
<td class="day">29</td>
<td class="day">30</td>
<td class="day">31</td>
<td class="day day--hole">1</td>
<td class="day day--hole">2</td>
</tr>
</tbody>
</table>
.day has text-align: right; on it. Set that to text-align: center;

How to move backgroung with repeating-linear-gradient()

It's a bit complicated for me to explain this by words, so please look at
table {
border-collapse: collapse;
}
table>tbody td {
border: solid 1px #00000062;
width: 47px;
height: 34px;
text-align: center;
}
#t1 td.locked {
background: repeating-linear-gradient(-45deg, transparent, transparent 7px, #00000035 7px, #00000035 14px);
}
/**
* I have no success with this
*/
#t1 td.locked:nth-child(odd) {
background-position-y: 0px;
}
#t2 td {
width: 45px;
height: 25px;
}
#t2 td.locked {
background: repeating-linear-gradient(-49deg, transparent, transparent 9px, #00000035 9px, #00000035 18px);
}
<table id="t1">
<tbody>
<tr>
<td>1.1</td>
<td class="locked">1.2</td>
<td class="locked">1.3</td>
<td class="locked">1.4</td>
<td>1.5</td>
</tr>
<tr>
<td>2.1</td>
<td class="locked">2.2</td>
<td class="locked">2.3</td>
<td class="locked">2.4</td>
<td>2.5</td>
</tr>
<tr>
<td>3.1</td>
<td class="locked">3.2</td>
<td class="locked">3.3</td>
<td class="locked">3.4</td>
<td>3.5</td>
</tr>
<tr>
<td>4.1</td>
<td class="locked">4.2</td>
<td class="locked">4.3</td>
<td class="locked">4.4</td>
<td>4.5</td>
</tr>
<tr>
<td>5.1</td>
<td class="locked">5.2</td>
<td class="locked">5.3</td>
<td class="locked">5.4</td>
<td>5.5</td>
</tr>
</tbody>
</table>
<hr>
<table id="t2">
<tbody>
<tr>
<td>1.1</td>
<td class="locked">1.2</td>
<td class="locked">1.3</td>
<td class="locked">1.4</td>
<td>1.5</td>
</tr>
<tr>
<td>2.1</td>
<td class="locked">2.2</td>
<td class="locked">2.3</td>
<td class="locked">2.4</td>
<td>2.5</td>
</tr>
<tr>
<td>3.1</td>
<td class="locked">3.2</td>
<td class="locked">3.3</td>
<td class="locked">3.4</td>
<td>3.5</td>
</tr>
<tr>
<td>4.1</td>
<td class="locked">4.2</td>
<td class="locked">4.3</td>
<td class="locked">4.4</td>
<td>4.5</td>
</tr>
<tr>
<td>5.1</td>
<td class="locked">5.2</td>
<td class="locked">5.3</td>
<td class="locked">5.4</td>
<td>5.5</td>
</tr>
</tbody>
</table>
There are two tables with some cells having striped background.
Striped cells in #t2 are nearly what I want: stripes in neighboring cells almost coincide and look like that they are drawn across the whole column (or several columns).
But I don't like how I've achieved this: by adjusting cells size and stripes width and angle.
Is it possible to achieve similar look for #t1 table by somehow "move" striped background? And don't change stripes width and angle and cells size also?
You may apply the gradient to the whole table instead and apply white background to the cell where you don't need the gradient.
table {
border-collapse: collapse;
background: repeating-linear-gradient(-45deg, transparent, transparent 7px, #00000035 7px, #00000035 14px);
}
table>tbody td {
border: solid 1px #00000062;
width: 47px;
height: 34px;
text-align: center;
}
td:not(.locked) {
background:#fff;
}
#t2 td {
width: 45px;
height: 25px;
}
<table id="t1">
<tbody>
<tr>
<td>1.1</td>
<td class="locked">1.2</td>
<td class="locked">1.3</td>
<td class="locked">1.4</td>
<td>1.5</td>
</tr>
<tr>
<td>2.1</td>
<td class="locked">2.2</td>
<td class="locked">2.3</td>
<td class="locked">2.4</td>
<td>2.5</td>
</tr>
<tr>
<td>3.1</td>
<td class="locked">3.2</td>
<td class="locked">3.3</td>
<td class="locked">3.4</td>
<td>3.5</td>
</tr>
<tr>
<td>4.1</td>
<td class="locked">4.2</td>
<td class="locked">4.3</td>
<td class="locked">4.4</td>
<td>4.5</td>
</tr>
<tr>
<td>5.1</td>
<td class="locked">5.2</td>
<td class="locked">5.3</td>
<td class="locked">5.4</td>
<td>5.5</td>
</tr>
</tbody>
</table>
<hr>
<table id="t2">
<tbody>
<tr>
<td>1.1</td>
<td class="locked">1.2</td>
<td class="locked">1.3</td>
<td class="locked">1.4</td>
<td>1.5</td>
</tr>
<tr>
<td>2.1</td>
<td class="locked">2.2</td>
<td class="locked">2.3</td>
<td class="locked">2.4</td>
<td>2.5</td>
</tr>
<tr>
<td>3.1</td>
<td class="locked">3.2</td>
<td class="locked">3.3</td>
<td class="locked">3.4</td>
<td>3.5</td>
</tr>
<tr>
<td>4.1</td>
<td class="locked">4.2</td>
<td class="locked">4.3</td>
<td class="locked">4.4</td>
<td>4.5</td>
</tr>
<tr>
<td>5.1</td>
<td class="locked">5.2</td>
<td class="locked">5.3</td>
<td class="locked">5.4</td>
<td>5.5</td>
</tr>
</tbody>
</table>
You need to set a common point of reference for the background.
The style needed for this is
background-attachment: fixed
table {
border-collapse: collapse;
}
table>tbody td {
border: solid 1px #00000062;
width: 47px;
height: 34px;
text-align: center;
}
#t1 td.locked {
background: repeating-linear-gradient(-45deg, transparent, transparent 7px, #00000035 7px, #00000035 14px);
background-attachment: fixed; /* added */
}
<table id="t1">
<tbody>
<tr>
<td>1.1</td>
<td class="locked">1.2</td>
<td class="locked">1.3</td>
<td class="locked">1.4</td>
<td>1.5</td>
</tr>
<tr>
<td>2.1</td>
<td class="locked">2.2</td>
<td class="locked">2.3</td>
<td class="locked">2.4</td>
<td>2.5</td>
</tr>
<tr>
<td>3.1</td>
<td class="locked">3.2</td>
<td class="locked">3.3</td>
<td class="locked">3.4</td>
<td>3.5</td>
</tr>
<tr>
<td>4.1</td>
<td class="locked">4.2</td>
<td class="locked">4.3</td>
<td class="locked">4.4</td>
<td>4.5</td>
</tr>
<tr>
<td>5.1</td>
<td class="locked">5.2</td>
<td class="locked">5.3</td>
<td class="locked">5.4</td>
<td>5.5</td>
</tr>
</tbody>
</table>
<hr>

Column width glitch with contenteditable

Appears in firefox only. Just add linebreak at the beginning of 1 cell to see what happens, or see screenshot.
What I want:
1. Column width must stay constant
2. Table must grow only in height
<style>
td {
white-space: pre-wrap;
word-break: break-all;
width: 200px;
}
</style>
<table border="1">
<caption>Таблица размеров обуви</caption>
<tr>
<th>Россия</th>
<th>Великобритания</th>
<th>Европа</th>
<th>Длина ступни, см</th>
</tr>
<tr>
<td contenteditable="true">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td>
<td contenteditable="true">3,5</td>
<td contenteditable="true">36</td>
<td contenteditable="true">23</td>
</tr>
<tr>
<td contenteditable="true">35,5</td>
<td contenteditable="true">4</td>
<td contenteditable="true">36⅔</td>
<td contenteditable="true">23–23,5</td>
</tr>
<tr>
<td contenteditable="true">36</td>
<td contenteditable="true">4,5</td>
<td contenteditable="true">37⅓</td>
<td contenteditable="true">23,5</td>
</tr>
<tr>
<td contenteditable="true">36,5</td>
<td contenteditable="true">5</td>
<td contenteditable="true">38</td>
<td contenteditable="true">24</td>
</tr>
<tr>
<td contenteditable="true">37</td>
<td contenteditable="true">5,5</td>
<td contenteditable="true">38⅔</td>
<td contenteditable="true">24,5</td>
</tr>
<tr>
<td contenteditable="true">38</td>
<td contenteditable="true">6</td>
<td contenteditable="true">39⅓</td>
<td contenteditable="true">25</td>
</tr>
<tr>
<td contenteditable="true">38,5</td>
<td contenteditable="true">6,5</td>
<td contenteditable="true">40</td>
<td contenteditable="true">25,5</td>
</tr>
<tr>
<td contenteditable="true">39</td>
<td contenteditable="true">7</td>
<td contenteditable="true">40⅔</td>
<td contenteditable="true">25,5–26</td>
</tr>
<tr>
<td contenteditable="true">40</td>
<td contenteditable="true">7,5</td>
<td contenteditable="true">41⅓</td>
<td contenteditable="true">26</td>
</tr>
<tr>
<td contenteditable="true">40,5</td>
<td contenteditable="true">8</td>
<td contenteditable="true">42</td>
<td contenteditable="true">26,5</td>
</tr>
<tr>
<td contenteditable="true">41</td>
<td contenteditable="true">8,5</td>
<td contenteditable="true">42⅔</td>
<td contenteditable="true">27</td>
</tr>
<tr>
<td contenteditable="true">42</td>
<td contenteditable="true">9</td>
<td contenteditable="true">43⅓</td>
<td contenteditable="true">27,5</td>
</tr>
<tr>
<td contenteditable="true">43</td>
<td contenteditable="true">9,5</td>
<td contenteditable="true">44</td>
<td contenteditable="true">28</td>
</tr>
<tr>
<td contenteditable="true">43,5</td>
<td contenteditable="true">10</td>
<td contenteditable="true">44⅔</td>
<td contenteditable="true">28–28,5</td>
</tr>
<tr>
<td contenteditable="true">44</td>
<td contenteditable="true">10,5</td>
<td contenteditable="true">45⅓</td>
<td contenteditable="true">28,5–29</td>
</tr>
<tr>
<td contenteditable="true">44,5</td>
<td contenteditable="true">11</td>
<td contenteditable="true">46</td>
<td contenteditable="true">29</td>
</tr>
<tr>
<td contenteditable="true">45</td>
<td contenteditable="true">11,5</td>
<td contenteditable="true">46⅔</td>
<td contenteditable="true">29,5</td>
</tr>
<tr>
<td contenteditable="true">46</td>
<td contenteditable="true">12</td>
<td contenteditable="true">47⅓</td>
<td contenteditable="true">30</td>
</tr>
<tr>
<td contenteditable="true">46,5</td>
<td contenteditable="true">12,5</td>
<td contenteditable="true">48</td>
<td contenteditable="true">30,5</td>
</tr>
<tr>
<td contenteditable="true">47</td>
<td contenteditable="true">13</td>
<td contenteditable="true">48⅔</td>
<td contenteditable="true">31</td>
</tr>
<tr>
<td contenteditable="true">48</td>
<td contenteditable="true">13,5</td>
<td contenteditable="true">49⅓</td>
<td contenteditable="true">31,5</td>
</tr>
</table>
</body>
</html>
https://jsfiddle.net/s8q0evkf/
Use max-width to set a maximum width
td {
white-space: pre-wrap;
word-break: break-all;
width: 200px;
max-width: 200px;
}
The overflowing content will now overflow in height instead of the width.
Documentation: http://www.w3schools.com/cssref/pr_dim_max-width.asp

how to create table grid view fix header with long title name using only CSS?

I am trying to make table grid view using CSS only. But when I make long title name design gets distorted.
Here's the Code:
.table {
table-layout:fixed;
width:500px;
border-collapse:collapse;
}
.header th {
font-family:Calibri;
font-size:small;
font-weight:lighter;
border-left:1px solid #000;
background:#d0d0d0;
}
.body_panel {
display:inline-block;
width:520px;
height:300px;
overflow-y:scroll;
}
.body tr {
border-bottom:1px solid #d0d0d0;
}
.body td {
border-left:1px solid #d0d0d0;
padding-left:3px;
font-family:Calibri;
font-size:small;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}
<table class="table">
<thead class="header">
<tr>
<th style="width:20%;">vijay solanki vijayksolanki</th>
<th style="width:30%;">vijay solanki vijaysolanki</th>
<th style="width:50%;">vijay solanki vijaysolanki</th>
</tr>
</thead>
</table>
<div class="body_panel">
<table class="table">
<tbody class="body">
<tr>
<td style="width:20%;">asbkj k kajsb ksb kabkb</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
<tr>
<td style="width:20%;">2</td>
<td style="width:30%;">2</td>
<td style="width:50%;">3</td>
</tr>
</tbody>
</table>
Please help me into this.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cruise Ships, their Tonnage and Status</title>
<style type="text/css">
* { padding: 0; margin: 0; }
table.cruises {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
cellspacing: 0;
border-collapse: collapse;
width: 535px;
}
table.cruises td {
border-left: 1px solid #999;
border-top: 1px solid #999;
padding: 2px 4px;
}
table.cruises tr:first-child td {
border-top: none;
}
table.cruises th {
width:50px!important;
border-left: 1px solid #999;
padding: 2px 4px;
background: #6b6164;
color: white;
font-variant: small-caps;
}
table.cruises td { background: #eee; overflow: hidden; }
div.scrollableContainer {
position: relative;
width: 592px;
padding-top: 2em;
margin: 40px;
border: 1px solid #999;
background: #6b6164;
}
div.scrollingArea {
height: 240px;
overflow: auto;
}
table.scrollable thead tr {
left: -1px; top: 0;
position: absolute;
}
table.cruises .name div { width: 108px; }
table.cruises .operator div { width: 126px; }
table.cruises .began div { width: 76px; text-align:center; }
table.cruises .tonnage div { width: 60px; text-align:center; }
table.cruises .status div { width: 160px; }
table.cruises td.operator { background: #ebcb4d; }
table.cruises td.tonnage { background: white; }
table.cruises td.name { background: #C7E0C1; }
table.cruises td.began { background: #B7C3E8; }
</style>
</head>
<body>
<div class="scrollableContainer">
<div class="scrollingArea">
<table class="cruises scrollable">
<thead>
<tr>
<th class="name"><div>Name defffdbre fgrgfergfer fgrgfergfer</div></th>
<th class="operator"><div>Operator</div></th>
<th class="began"><div>Name defffdbre fgrgfergfer fgrgfergfer</div></th>
<th class="tonnage"><div>Tonnage</div></th>
<th class="status"><div>Status</div></th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><div>Seabourne Sun</div></td>
<td class="operator"><div>Seabourn Cruise Line</div></td>
<td class="began"><div>1988</div></td>
<td class="tonnage"><div></div></td>
<td class="status"><div >Ended service in 2002, currently operating as Prinsendam</div></td>
</tr>
<tr>
<td class="name"><div>Adventures of the Seas</div></td>
<td class="operator"><div>Royal Caribbean International</div></td>
<td class="began"><div>2001</div></td>
<td class="tonnage"><div>138,000</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Oceanic Independence</div></td>
<td class="operator"><div>American Hawaiian Cruises / American Global Line</div></td>
<td class="began"><div>1974</div></td>
<td class="tonnage"><div>23,719</div></td>
<td class="status"><div >Named formerly (1951-1974) and subsequently renamed (1982-2006) the Independence, renamed the Oceanic (2006), sold for scrap in 2008 but remains in mothballs</div></td>
</tr>
<tr>
<td class="name"><div>Cunard Ambassador</div></td>
<td class="operator"><div>Cunard Line</div></td>
<td class="began"><div>1972</div></td>
<td class="tonnage"><div>14,160</div></td>
<td class="status"><div >Burnt 1974, rebuilt into a livestock carrier, renamed Linda Clausen, later Procyon, Raslan. Scrapped 1984 after a second fire.</div></td>
</tr>
<tr>
<td class="name"><div>Aegean Beauty</div></td>
<td class="operator"><div>Voyages to Antiquity</div></td>
<td class="began"><div>1973</div></td>
<td class="tonnage"><div>11,563</div></td>
<td class="status"><div >Formerly Aegean Dolphin and Aegean I. Operating</div></td>
</tr>
<tr>
<td class="name"><div>Serenade of the Seas</div></td>
<td class="operator"><div>Royal Caribbean International</div></td>
<td class="began"><div>2003</div></td>
<td class="tonnage"><div>90,090</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Queen Elizabeth 2</div></td>
<td class="operator"><div>Cunard Line</div></td>
<td class="began"><div>1969</div></td>
<td class="tonnage"><div>70,327</div></td>
<td class="status"><div >Left fleet in November 2008</div></td>
</tr>
<tr>
<td class="name"><div>Queen Elizabeth</div></td>
<td class="operator"><div>Cunard Line</div></td>
<td class="began"><div>2010</div></td>
<td class="tonnage"><div>92,000</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Regent Sea</div></td>
<td class="operator"><div>Regency Cruises</div></td>
<td class="began"><div>1957</div></td>
<td class="tonnage"><div></div></td>
<td class="status"><div >Began operation in 1957 as the Gripsholm (II) for Swedish America Line. Ended operation when Regency went bankrupt in 1995. Was to be converted to a casino ship, but later marked for scrap. Prior to scrapping, was looted by pirates, then sank in heavy seas in 2001.</div></td>
</tr>
<tr>
<td class="name"><div>Allure of the Seas</div></td>
<td class="operator"><div>Royal Caribbean International</div></td>
<td class="began"><div>2010</div></td>
<td class="tonnage"><div>225,000</div></td>
<td class="status"><div >Starts service in December 2010</div></td>
</tr>
<tr>
<td class="name"><div>Amadea</div></td>
<td class="operator"><div>Phoenix Reisen</div></td>
<td class="began"><div>2006</div></td>
<td class="tonnage"><div>28,717</div></td>
<td class="status"><div >Operating. Ex-Asuka</div></td>
</tr>
<tr>
<td class="name"><div>Amant</div></td>
<td class="operator"><div>PhoenixVoyages (Vietnam)</div></td>
<td class="began"><div>2010</div></td>
<td class="tonnage"><div></div></td>
<td class="status"><div >Built in 2010 by a local Vietnamese shipyard (Vuotsong), L'Amant operates on the Mekong River in Vietnam, and is without any doubt the most well constructed vessel sailing in Vietnam.</div></td>
</tr>
<tr>
<td class="name"><div>Oasis of the Seas</div></td>
<td class="operator"><div>Royal Caribbean Cruise Line</div></td>
<td class="began"><div>2009</div></td>
<td class="tonnage"><div>225,282</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Andes</div></td>
<td class="operator"><div>Royal Mail Lines</div></td>
<td class="began"><div>1959</div></td>
<td class="tonnage"><div>27,000</div></td>
<td class="status"><div >Was liner, became cruise ship in 1959.</div></td>
</tr>
<tr>
<td class="name"><div>Anna Nery</div></td>
<td class="operator"><div>Companhia de Navegacao Costeirab</div></td>
<td class="began"><div>1962</div></td>
<td class="tonnage"><div></div></td>
<td class="status"><div >Ended service in 1978. Currently operating as Salamis Glory</div></td>
</tr>
<tr>
<td class="name"><div>National Geographic Endeavour</div></td>
<td class="operator"><div>Lindblad Expeditions</div></td>
<td class="began"><div>1996</div></td>
<td class="tonnage"><div></div></td>
<td class="status"><div >Operating, also known as Endeavour</div></td>
</tr>
<tr>
<td class="name"><div>Liberty of the Seas</div></td>
<td class="operator"><div>Royal Caribbean International</div></td>
<td class="began"><div>2007</div></td>
<td class="tonnage"><div>154,407</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Norwegian Epic</div></td>
<td class="operator"><div>Norwegian Cruise Line</div></td>
<td class="began"><div>2010</div></td>
<td class="tonnage"><div>153,000</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Independence of the Seas</div></td>
<td class="operator"><div>Royal Caribbean International</div></td>
<td class="began"><div>2008</div></td>
<td class="tonnage"><div>154,407</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Navigator of the Seas</div></td>
<td class="operator"><div>Royal Caribbean International</div></td>
<td class="began"><div>2002</div></td>
<td class="tonnage"><div> 138,000</div></td>
<td class="status"><div >Operating</div></td>
</tr>
<tr>
<td class="name"><div>Caribbean Princess</div></td>
<td class="operator"><div>Princess Cruises</div></td>
<td class="began"><div>2004</div></td>
<td class="tonnage"><div>112,894</div></td>
<td class="status"><div >Operating</div></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

Resources