CSS calc not working for <td> width - html

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>

Related

How can I create a litter square at the right-bottom of a border table cell?

How can I add a little square at the bottom right of a table cell?
It just like a selected cell in excel.
I have tried to add a div in the cell, however, it makes the content does not be placed in the centre of the cell. So, I don't know how to do so.
HTML:
.borderCell
{
border:1px inset #e0e0e0;
}
.borderCell:after
{
border:2px inset transparent;
}
.dateCell
{
padding: 0px;
font-size:17px;
width:25px;
}
<table>
<tr>
<td class="borderCell alignCenter" contenteditable="true">
b
<div style="width:5px;height:5px;background-color:blue;float:right"></div>
</td>
</tr>
</table>
table {
border-collapse: collapse;
}
table,
th,
td {
border: 1px solid black;
}
th,
td {
padding: 10px;
}
td.parentsqure {
position: relative;
}
.squre {
height: 5px;
width: 5px;
background: red;
position: absolute;
right: 0;
bottom: 0;
}
<table>
<tr>
<td>test 1</td>
<td class="parentsqure">
test 2
<div class="squre"></div>
</td>
<td>test 3</td>
</tr>
</table>
No need to consider an extra element, use a simple background:
table {
border-collapse: collapse;
}
table,
th,
td {
border: 1px solid black;
}
th,
td {
padding: 10px;
}
td.parentsqure {
background: linear-gradient(red,red) bottom right/5px 5px no-repeat;
}
<table>
<tr>
<td>test 1</td>
<td class="parentsqure">
test 2
</td>
<td>test 3</td>
</tr>
</table>

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>

How to separate row in table using border

I have a table in which I have to separate a row using border as in image below.
As you can see, Border separator is having a space left-right side and not fully touched to table border.
I tried giving padding,margin but nothing worked.
tr {
border-bottom: 1px solid blue;
padding: 10px; // not working
margin: 10px; // not working
}
https://jsfiddle.net/alpeshprajapati/s934Lpbx/
What is the way to achieve this?
CSS
table {
border: 1px solid black;
border-collapse: collapse;
}
thead {
background: black;
color: white;
}
th {
width: 100px;
}
tr {
float: left;
border-bottom: 1px solid blue;
width: 90%;
margin: 0 10px;
}
td{
width: 32%;
float: left;
}
Try this:
table {
border: 1px solid black;
border-collapse: collapse;
}
thead {
background: black;
color: white;
}
th {
width: 100px;
}
tr {
// border-bottom: 1px solid blue;
}
td{
padding:5px 10px;
}
.border{
background:skyblue;
width:100%;
height:2px;
}
<table>
<thead>
<th>Th1</th>
<th>Th2</th>
<th>Th3</th>
</thead>
<tbody>
<tr>
<td>TD1</td>
<td>TD2</td>
<td>TD3</td>
</tr>
<tr>
<td colspan="3">
<div class="border"></div>
</td>
</tr>
<tr>
<td>TD1</td>
<td>TD2</td>
<td>TD3</td>
</tr>
<tr>
<td colspan="3">
<div class="border"></div>
</td>
</tr>
<tr>
<td>TD1</td>
<td>TD2</td>
<td>TD3</td>
</tr>
</tbody>
</table>
To increase the length of the border you have to increase the width of the div that is containing it.

Setting table height appears to adds margin-top instead

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.

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;
}