Setting table height appears to adds margin-top instead - html

I'm trying to make a scrollable table, with the table height set. However, when I try to set the height, it adds a margin on top of the table instead of adjusting the height of the actual table.
I want only the table to scroll (Not the date above it) and eventually hope to make the column titles sticky.
You can see what I'm talking about here: http://jsfiddle.net/m5s87hb0/
This is my html:
<div class='box-style-1' id='timesheet-box'>
<span class='box-title'>Time Sheet<span>
<div id='table-wrapper'>
<table id='timesheet'>
<thead>
<th id='timesheet-date' colspan="5">00/00/0000 - 00/00/0000</th>
</thead>
<div id='table-scroll'>
<tbody>
<tr id='col-titles'>
<th>Jobs</th>
<th>Task</th>
<th>In</th>
<th>Out</th>
<th>Hours</th>
</tr>
<tr>
<td>Job 1</td>
<td>Task 1</td>
<td>00:00</td>
<td>00:00</td>
<td>0</td>
</tr>
<tr>
<td>Job 2</td>
<td>Task 2</td>
<td>00:00</td>
<td>00:00</td>
<td>0</td>
</tr>
<tr>
<td>Job 3</td>
<td>Task 3</td>
<td>00:00</td>
<td>00:00</td>
<td>0</td>
</tr>
<tr>
<td>Job 4</td>
<td>Task 4</td>
<td>00:00</td>
<td>00:00</td>
<td>0</td>
</tr>
<tr>
<td>Job 5</td>
<td>Task 5</td>
<td>00:00</td>
<td>00:00</td>
<td>0</td>
</tr>
</tbody>
</div>
</table>
</div>
</div>
Css:
.box-style-1 {
clear: both;
position: absolute;
display: block;
border: 1px solid black;
border-radius: 10px;
white-space: nowrap;
background: #D1D3D4;
overflow: hidden;
}
.box-title {
display: block;
background: #D15F32;
padding: 0px;
border-radius: 10px 10px 0px 0px;
text-align: center;
font-weight: ;
color: #fff;
font-size: 25px;
margin-bottom: 0px;
height: 40px;
padding-top: 10px;
}
#timesheet-box {
width: 78%;
height: 300px;
position: absolute;
display: block;
margin-left: 7%;
}
#table-wrapper {
position: relative;
height: 250px;
}
#timesheet {
width: 100%;
margin-top: 10px;
color: #3a3a3c;
height: 100%;
}
#timesheet-date {
padding: 0px;
margin-top: 50px;
}
#table-scroll {
position: relative;
display: block;
height: 100px;
overflow: scroll;
}
tbody {
}
th, td {
border: 1px solid #3a3a3c;
font-style: normal;
font-size: 22px;
height: 40px;
}
table {
border-collapse: collapse;
}

You can't have the div around tbody, move it around the table and your table will scroll
<div id='table-scroll'>
<table id='timesheet'>
...
</table>
</div>
edit
http://codepen.io/anon/pen/VLmqbK
To fix the header, you must add a position absolute to the header and fix its height. The rest of your table will go up so add a padding-top to the around div for this height value to fix it. Also add a background to hide scrolled content below.
thead {
position:absolute;
top:0px;
height:40px;
background:white;
}
#table-scroll {
display: block;
height: 200px;
overflow-y: scroll;
padding-top:23px; /* I don't know where the 17 other px come from in your code but who cares :) */
}

I solved the problem by moving the date out of the table.

Related

CSS calc not working for <td> width

I'd like Cell A to leave exactly 100px for the remain two cells. I would think calc(100% - 100px) would be sufficient as this works just fine in many other situations. Why isn't it working here?
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #555;
font-family: sans-serif;
table-layout: fixed;
}
td {
padding: 10px;
box-sizing: border-box;
text-align: center
}
td+td {
border-left: 1px solid #555;
}
td:first-child {
width: calc(100% - 100px);
}
<table>
<tbody>
<tr>
<td>Cell A</td>
<td>Cell B</td>
<td>Cell C</td>
</tr>
</tbody>
</table>
At least in Chrome, it seems to work when defining the width on a colgroup element:
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #555;
font-family: sans-serif;
table-layout: fixed;
}
td {
padding: 10px;
box-sizing: border-box;
text-align: center
}
td+td {
border-left: 1px solid #555;
}
colgroup:first-child {
width: calc(100% - 100px);
}
<table>
<colgroup/>
<colgroup span="2" />
<tbody>
<tr>
<td>Cell A</td>
<td>Cell B</td>
<td>Cell C</td>
</tr>
</tbody>
</table>
Update April 1st, 2020
This no longer seems to work in the current version of Chrome. I'll leave the answer to serve as a test case should the behavior change in the future.
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #555;
font-family: sans-serif;
table-layout: fixed;
}
td {
padding: 10px;
box-sizing: border-box;
text-align: center
}
td+td {
border-left: 1px solid #555;
}
td:first-child{
width: calc(100% / 6 * 3.5);
}
<table>
<tbody>
<tr>
<td>Cell A</td>
<td>Cell B</td>
<td>Cell C</td>
</tr>
</tbody>
</table>

How to make a dynamic table cell use overflow:hidden

I want to use overflow:hidden on a dynamic table that should only be as wide as necessary:
<table>
<tr>
<td>Should_not_overflow</td>
</tr>
<tr>
<td style="overflow: hidden;">This text should overflow please</td>
</tr>
</table>
I know that it works with a fixed table layout, but I need a dynamic table.
I also know that it would work with a fixed width and a nested <div>, but again, I need a dynamic table layout.
.table-wrapper {
font-size:12px;
position: relative;
width: 50%;
height: 275px;
border: 1px solid #333;
padding: 50px 0 0;
margin: 10px auto;
}
.header-bg {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 50px;
background-color: #03A9F4;
}
.table-container {
overflow-x: hidden;
overflow-y: auto;
height: 100%;
}
table {
width: 100%;
background-color: #FFF;
overflow-x: hidden;
overflow-y: auto;
}
tr {
&:nth-child(even) {
background-color: #F2F2F2;
}
th {
text-align: left;
padding: 0 5px;
.th-extra {
width: 100%;
.th-extra__inner {
position: absolute;
top: 0;
color: #000;
line-height: 50px;
text-align: left;
border-left: 1px solid #333;
padding: 0 0 0 5px;
margin: 0 0 0 -5px;
}
}
&:first-child {
.th-extra__inner {
border: none;
}
}
}
}
td {
line-height: 42px;
text-align: left;
padding: 0 5px;
& + td {
border-left: 1px solid #333;
}
}
<div class="table-wrapper">
<div class="header-bg"></div>
<div class="table-container">
<table cellspacing="0">
<thead>
<tr>
<th>
<div class="th-extra">
<div class="th-extra__inner">First</div>
</div>
</th>
<th>
<div class="th-extra">
<div class="th-extra__inner">Second</div>
</div>
</th>
<th>
<div class="th-extra">
<div class="th-extra__inner">Third</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column with longer content</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
<tr>
<td>Column</td>
<td>Column</td>
<td>Column</td>
</tr>
</tbody>
</table>
</div>
</div>

CSS table border-bottom not showing

My goal is to add a bottom white line border under the heading in css as such shown in this picture table image. However the border is not appearing. I was watching and coding along a youtube tutorial on html and css. My results were fine until I reached the part where he added the bottom white line border tutorial video at 1hr34min45sec. When I placed the bottom border, it didn't appear.
Any help would be appreciated
.tile {
width: 170px;
border-radius: 2%;
height: 140px;
padding: 20px;
margin: 5px;
float:left;
}
.tile-double {
width: 390px;
height: 140px;
margin: 5px;
padding: 20;
float: left;
}
.orange {
background-color: #e61860;
}
#user-table {
border-collapse: collapse;
margin: 10px auto;
font-weight: normal;
width: 100%;
}
#user-table th{
border-collapse: collapse;
border-bottom: 1xp solid #F6F6F6;
padding 2px;
text-align: center;s
}
#user-table td{
padding: 2px;
text-align: center;
}
<div class="tile orange tile-double">
<table id="user-table">
<thead>
<tr>
<th>User</th>
<th>Product</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr>
<td>FruitDealer</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
<tr>
<td>DongRaeGu</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
<tr>
<td>July</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
</tbody>
</table>
</div>
In my case, the user-agent style was overriding my css class with border-collapse property. So I had to override it using
table {
border-collapse: collapse;
}
Try to run your code through those validators, specifically:
border-bottom: 1xp solid #F6F6F6; /* shows xp instead of px (pixels) */
https://validator.w3.org/ -- for HTML
https://jigsaw.w3.org/css-validator/ -- for CSS
Try targeting the tr of the thead so the border fills the full width of your table.
thead tr { border-bottom: 1px solid #FFF; }
Okay I checked out your css there are minor errors in it check out
#user-table th{
border-collapse: collapse;
border-bottom: 1xp solid #F6F6F6; --- should be 1px not 1xp this one here was your main problem this is why the border didn't show up
padding 2px; ----- incorrect should be paddin: 2px;
text-align: center;s --- the s shouldn't be there
}
.tile {
width: 170px;
border-radius: 2%;
height: 140px;
padding: 20px;
margin: 5px;
float:left;
}
.tile-double {
width: 390px;
height: 140px;
margin: 5px;
padding: 20;
float: left;
}
.orange {
background-color: #e61860;
}
#user-table {
border-collapse: collapse;
margin: 10px auto;
font-weight: normal;
width: 100%;
}
#user-table th{
border-collapse: collapse;
border-bottom: 1xp solid #F6F6F6;
padding 2px;
text-align: center;s
}
#user-table td{
padding: 2px;
text-align: center;
}
<div class="tile orange tile-double">
<table id="user-table">
<thead>
<tr>
<th>User</th>
<th>Product</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr>
<td>FruitDealer</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
<tr>
<td>DongRaeGu</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
<tr>
<td>July</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
</tbody>
</table>
</div>
.tile {
width: 170px;
border-radius: 2%;
height: 140px;
padding: 20px;
margin: 5px;
float:left;
}
.tile-double {
width: 390px;
height: 140px;
margin: 5px;
padding: 20;
float: left;
}
.orange {
background-color: #e61860;
}
#user-table {
border-collapse: collapse;
margin: 10px auto;
font-weight: normal;
width: 100%;
}
#user-table th{
border-collapse: collapse;
border-bottom: 1xp solid #F6F6F6;
padding 2px;
text-align: center;s
}
#user-table td{
padding: 2px;
text-align: center;
}
<div class="tile orange tile-double">
<table id="user-table">
<thead>
<tr>
<th>User</th>
<th>Product</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr>
<td>FruitDealer</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
<tr>
<td>DongRaeGu</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
<tr>
<td>July</td>
<td>Razor Banshee</td>
<td>100%</td>
</tr>
</tbody>
</table>
</div>

Table with sticky column - Issue with cell size

I have a table that can slide left or right when the screen is narrow enough. The first column is positioned absolute so that it is always visible.
Is it possible to make the cells in the first column maintain the size of the cells in the other columns? I am not sure how to achieve this while keeping the first column frozen.
Here is a fiddle to my code: http://jsfiddle.net/ta945/
Here's the HTML and CSS
HTML:
<div>
<table>
<thead>
<tr>
<th class="sticky">Name</th>
<th>Helpful Services</th>
<th>State</th>
<th>City</th>
<th>Phone</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="sticky">First Name</td>
<td>Math</td>
<td>CO</td>
<td>San Francisco</td>
<td>123-456-7890</td>
<td>http://somewhere.com</td>
</tr>
<tr>
<td class="sticky">Second Name</td>
<td>Reading</td>
<td>NY</td>
<td>New York City</td>
<td>123-456-7890</td>
<td>http://somewhere.com</td>
</tr>
<tr>
<td class="sticky">Third Name</td>
<td>Art</td>
<td>IL</td>
<td>Chicago</td>
<td>123-456-7890</td>
<td>http://somewhere.com</td>
</tr>
<tr>
<td class="sticky">Four Name</td>
<td>Programming</td>
<td>IL</td>
<td>Chicago</td>
<td>123-456-7890</td>
<td>http://somewhere.com</td>
</tr>
</tbody>
</table>
</div>
CSS:
div {
width: 100%;
border: 1px solid #000000;
overflow-y: hidden;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
}
table {
border-collapse: seperate;
border-spacing: 0;
margin-left: 5em;
}
thead, tbody, tr {
vertical-align: middle;
}
th {
font-weight: bold;
padding: 2px 4px;
background-color: #676767;
color: #FFFFFF
}
td {
padding: 2px 4px;
}
tbody tr:nth-child(even) td {
background-color: #cccccc;
}
.sticky {
position: absolute;
left: 0;
top: auto;
margin-left: 9px;
}

td adding extra margin or padding to right of element

On an assignment for my teacher, we are making a table in which I want each td element to be 200px wide for a total of 5 cells which equal to 1000px (wrapper). When I do this however, the last td in each tr jumps down to the next line when they should all line up properly with no issues.
EDIT: Solved! (Read comments)
Here is my code for the table:
<table id="assignment-table">
<tr>
<th>Assignment</th>
<th>Fall 2013</th>
<th>Responsive?</th>
<th>Winter 2014</th>
<th>Responsive?</th>
</tr>
<tr>
<td>A1</td>
<td>Code Provided Site</td>
<td>No</td>
<td>Designasaurus</td>
<td>Yes</td>
</tr>
<tr>
<td>A2a</td>
<td>Restaurant Mock-up</td>
<td>N/a</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td>A2b</td>
<td>Restaurant Static</td>
<td>No</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td>A3a</td>
<td>Adaptive Excercise</td>
<td>No</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td>A3b</td>
<td>Responsive Excercise</td>
<td>Yes</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td>A4</td>
<td>Restaurant Final</td>
<td>Yes</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td>A5a</td>
<td>Final Mock-up</td>
<td>N/a</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td>A5b</td>
<td>Final Site</td>
<td>Yes</td>
<td>TBA</td>
<td>-</td>
</tr>
<tr>
<td class="lastrow">NSCC GRAPHIC DESIGN | 2012-14</td>
</tr>
</table>
</div>
And then the CSS:
#content {
width: 100%;
color: white;
}
#assignment-table {
font-size: 16px;
border-spacing: 0!important;
border-collapse: collapse;
}
#assignment-table th {
display: inline-block;
padding: 25px 0;
width: 200px;
text-align: center;
}
#assignment-table tr {
display: block;
border-bottom: 1px solid #ffffff;
}
#assignment-table tr:last-child {
width: 1000px;
border-bottom: none!important;
}
#assignment-table td {
display: inline-block;
padding: 25px 0;
width: 200px;
text-align: center;
}
.lastrow {
width: 1000px!important;
}
th:nth-child(3) {
background-color: rgba(255,255,255,0.05);
}
td:nth-child(3) {
background-color: rgba(255,255,255,0.05);
font-family: 'source_sans_proitalic';
}
th:nth-child(5) {
background-color: rgba(255,255,255,0.05);
}
td:nth-child(5) {
background-color: rgba(255,255,255,0.05);
font-family: 'source_sans_proitalic';
}
It should look like this:
It looks like you have display: inline-block; on your table cells. inline-block will automatically insert a space between elements. It's this space that is adding up and wrapping your last element. I would remove the display: inline-block; from your css entries, since this is a table it doesn't need it anyway.
CSS:
#assignment-table th {
//display: inline-block; <- remove this
padding: 25px 0;
width: 200px;
text-align: center;
}
#assignment-table td {
//display: inline-block; <- remove this
padding: 25px 0;
width: 200px;
text-align: center;
}
EXAMPLE FIDDLE
You are removing the default table behavior by using display: inline-block on tds. Just apply width: 1000px to the table and td { width: 20%; }
EDIT: here you go.