I have a table with 3 columns. I'd like to remove the border/cellspacing between the first and second columns, and make it appear like one column.
Fiddle: https://jsfiddle.net/o8x3ego0/1/
HTML
<table id="holdingsDistributionTable" class="table table-responsive">
<tr>
<th colspan="2">Currency</th>
<th>Value</th>
</tr>
<tr>
<td>
<div class="currencyHolder greenCurrencyHolder">
<div class="currency greenCurrency">
AED
</div>
</div>
</td>
<td>
<div style="text-align: center">
UA Emirates Dirham
</div>
</td>
<td>
<b>345</b>
</td>
</tr>
<tr>
<td>
<div class="currencyHolder blueCurrencyHolder">
<div class="currency blueCurrency">
ARS
</div>
</div>
</td>
<td>
<div style="text-align: center">
Argentine Peso
</div>
</td>
<td>45345</td>
</tr>
</table>
In the above example, I'd like to remove the spacing between the 1st and 2nd columns in the data rows.
You can remove the border from the entire table by:
table {
border-collapse: collapse;
}
Then to add borders to the rows, table headers and the last table cells (or whatever table cells necessary by using :nth-child):
tr, th, td:last-child {
border: 1px solid black; /* changed to black to be more noticeable */
}
Then remove padding from the table header and table cells:
th, td {
padding: 0;
}
Here is the updated fiddle.
edit: it was col and not row, so i believe this is more like this : https://jsfiddle.net/o8x3ego0/6/ (same method, but padding to draw the hole in between th )
you can use
border-collapse to remove cellspacing and to allow style tr borders
a line-height to th instead padding
draw a transparent border at bottom of th (padding works too)
and erase bg color with background-clip to mimic the border-spacing only where you want to
body {
background-color: white;
}
/* demo */
tr:nth-child(1) th {
border-bottom: 3px solid transparent;
background-clip: content-box
}
table {
border-collapse: collapse;
}
/* end */
.table {
margin-bottom: 20px;
}
.table-responsive {
width: 100%;
overflow-x: auto;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: -ms-autohiding-scrollbar;
border: 1px solid #ddd;
}
.currencyHolder {
padding: 7px;
border-radius: 5px;
border-width: 2px;
border-style: solid;
margin-top: 10px;
margin-bottom: 10px;
max-width: 36px;
text-align: center;
}
.currency {
border-radius: 5px;
color: white;
font-size: 11px;
font-weight: bold;
}
.greenCurrencyHolder {
background-color: green;
border-color: darkgreen;
}
.greenCurrency {
background-color: darkgreen;
}
.blueCurrencyHolder {
background-color: azure;
border-color: cadetblue;
}
.blueCurrency {
background-color: cadetblue;
}
#holdingsDistributionTable {
display: table;
/*width: 100% !important;*/
}
#holdingsDistributionTable th {
background-color: #F4F5F6;
color: #AAABAE;
line-height: 2.5em;
/* instead vertical padding */
width: 25%;
font-weight: normal;
}
#holdingsDistributionTable th:last-child,
#holdingsDistributionTable td:last-child {
background-color: #DFE1E3;
color: #A19D9E;
}
#holdingsDistributionTable td:last-child {
background-color: #DFE1E3;
color: black;
}
#holdingsDistributionTable th,
#holdingsDistributionTable td {
min-height: 15px;
background-color: #F4F5F6;
}
<table id="holdingsDistributionTable" class="table table-responsive">
<tr>
<th colspan="2">Currency</th>
<th>Value</th>
</tr>
<tr>
<td>
<div class="currencyHolder greenCurrencyHolder">
<div class="currency greenCurrency">
AED
</div>
</div>
</td>
<td>
<div style="text-align: center">
UA Emirates Dirham
</div>
</td>
<td>
<b>345</b>
</td>
</tr>
<tr>
<td>
<div class="currencyHolder blueCurrencyHolder">
<div class="currency blueCurrency">
ARS
</div>
</div>
</td>
<td>
<div style="text-align: center">
Argentine Peso
</div>
</td>
<td>45345</td>
</tr>
</table>
The best solution would be to make your table only two columns in the first place and do not use colspan="2" then make the stylized currency abbreviation line up with the currency name by setting the two div in each column inline block items using display: inline-block; in your CSS
Fiddle: https://jsfiddle.net/f30tujzn/
this solution is not only easier then removing part of your border but will render faster, and respond better on smaller devices.
Related
Browser does not display td with enough space to hold contents
I have a table cell whose content is a styled a tag. The height of the styled a tag is 29px high, but the content-height attribute of the td cell is 19px, that is the value of line-height for the font that is in use. I see this in the Firefox inspector. The styled a tag is higher than simple text because it has padding and borders. I do not understand why the browser has not included the padding and borders of the content in calculating the height and width of the td tag that is intended to hold the content. I do not want to explicitly set the height of the td in case I later change the style for the a tag. I cannot find any documentation of how the td, or any box, calculates the height of the content-area.
td.odd {
font-family: sans-serif;
background-color: #F8F8F8;
border-right: thin solid black;
border-bottom: thin solid black;
padding: 2px 2px 2px 2px;
empty-cells: show;
}
td.left {
text-align: left;
float: none;
}
td.center {
text-align: center;
float: none;
}
td.right {
text-align: right;
float: none;
}
a.button {
font-family: sans-serif;
font-weight: bold;
font-size: 80%;
text-align: center;
text-decoration: none;
background-color: #E0E0E0;
color: #000000;
border-top: 2px solid white;
border-left: 2px solid white;
border-bottom: 3px solid #606060;
border-right: 3px solid #606060;
padding: 4px 12px 4px 12px;
}
<tr id="location">
<td class="odd right">
<a href="Location.php?id=$IDLR&lang=$LANG" class="button">
Details
</a>
</td>
<td class="odd left">
$LOCATION
</td>
<td class="odd center">
$LOCPRESENT
</td>
<td class="odd center">
$NOTESPRESENT
</td>
<td class="odd center">
$BOUNDPRESENT
</td>
</tr>
An example of the page that is not displaying to my satisfaction is https://www.jamescobban.net/FamilyTree/Locations.php?pattern=%5EZephyr&namefld=
Note how the "button" in the first cell does not fit in the containing table cell.
I would expect the size of the content-area in the td to match the size of the actual element contained in the td. Instead the td is using some fictional element which is only the height of the text.
This is due to the display mode of the content of the cell. <a> elements display inline by default, so their height will be treated as the line height. In your example, try adding display: block or display: inline-block to the a.button rule.
Demo:
table, th, td {
border: 1px solid black;
}
.button {
background: #ddd;
padding: 5px;
border: 2px solid black;
}
.block {
display: block;
}
<h4>Bad Table:</h4>
<table><tr>
<td><a class="button">Button A</a></td>
<td>Another Cell 1</td>
</tr><tr>
<td><a class="button">Button B</a></td>
<td>Another Cell 2</td>
</tr></table>
<h4>Good Table:</h4>
<table><tr>
<td><a class="button block">Button A</a></td>
<td>Another Cell 1</td>
</tr><tr>
<td><a class="button block">Button B</a></td>
<td>Another Cell 2</td>
</tr></table>
I am using a Pandas DataFrame and I want to show it in a html page showing as less empty space as possible. I am also using Bootstrap 4
I can add formatters to all the elements of a column with the to_html method, and table styles:
html = df.to_html(
formatters={'COL_NAME': lambda x: '<b>' + x + '</b>'},
classes='table table-striped df_data',
escape=False
)
And I can add html elements as well replacing the values directly
html = html.replace('<th>', '<th><div><span>')
html = html.replace('</th>', '</span></div></th>')
Is there a clean way to add these html elements to the headers?
I am doing all of this to show rotated headers and save screen space as in the picture. I took the css styles from this page
.df_data thead th {
height: 140px;
white-space: nowrap;
}
.df_data thead th > div {
transform: translate(25px, 51px) rotate(315deg);
width: 30px;
}
.df_data thead th > div > span {
border-bottom: 1px solid #ccc;
padding: 5px 10px;
}
But the result is far from the expected. The space is not safed and the headers are not aligned. What I need to do to safe the free space in the columns? I will need to forget about Bootstrap styles
Is there a straight forward way to achieve this?
Any recommendation will be appreciated
Update 2019-26-02
The solution of #joshmoto is a good approach but I need adapting width columns because I do not know the cell contents beforehand (10 characters as maximum)
To get this desired effect when the cell width is variable, you will need to add another div and position that is position: relative; in the table header cell. From here you can position: absolute; the next child div left: 100%;, which will give you your right point of reference. Then you can continue to use the code you provided from the codepen demo.
See codeply working demo here https://www.codeply.com/go/RuEciHdXo3
MAIN {
padding-top: 30px;
padding-bottom: 30px
}
.df_data {
border-collapse: collapse
}
.df_data thead th {
border-top: none;
padding: 0
}
.df_data td {
text-align: center;
padding: 10px 5px;
border: 1px solid #ccc
}
.df_data th.rotate {
margin-left: 100%;
height: 140px;
white-space: nowrap
}
.df_data th.rotate>div {
position: relative;
width: 100%;
height: 30px
}
.df_data th.rotate>div>div {
position: absolute;
left: 100%;
width: 30px;
transform: translate(-14px, -2px) rotate(315deg)
}
.df_data th.rotate>div>div>span {
border-bottom: 1px solid #ccc;
padding: 5px 10px
}
.df_data th.row-header {
padding: 0 10px;
border-bottom: 1px solid #ccc
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<main role="main" class="container">
<table class="table table-striped df_data">
<thead>
<tr>
<th></th>
<th class="rotate">
<div>
<div><span>Column header 1</span></div>
</div>
</th>
<th class="rotate">
<div>
<div><span>Column header 2</span></div>
</div>
</th>
<th class="rotate">
<div>
<div><span>Column header 3</span></div>
</div>
</th>
<th class="rotate">
<div>
<div><span>Column header 4</span></div>
</div>
</th>
<th class="rotate">
<div>
<div><span>Column header 5</span></div>
</div>
</th>
<th class="rotate">
<div>
<div><span>Column header 6</span></div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<th class="row-header">Row header 1</th>
<td>2w98</td>
<td>3423423</td>
<td>35325233542947742747344</td>
<td>12213></td>
<td>453842589389582</td>
<td>49849</td>
</tr>
</tbody>
</table>
</main>
I am having a nested table which I am showing in the html. I am trying to have each column 50% Width but it is not working.
In the past when I need to do it, I apply table-layout: fixed and most of the time it works but this time it is not working.
What is wrong?
editor link
<table class="employment" *ngFor="let item of empTabData| slice:1">
<div class="container" fxLayout="row " fxLayout.xs="column">
<div class="item-1 " fxFlex="50%" fxFlex.xs="100%">
<tr *ngFor="let i of item.employerInfo | slice:0:(item.employerInfo.length/2)+1">
<td class="emp">
{{i.key}}
</td>
<td class="emp">
{{i.value}}
</td>
</tr>
</div>
<div class="item-1" fxFlex="50%" fxFlex.xs="100% ">
<tr *ngFor="let i of item.employerInfo | slice:(item.employerInfo.length/2)+1:item.employerInfo.length">
<td class="emp">
{{i.key}}
</td>
<td class="emp">
{{i.value}}
</td>
</tr>
</div>
</div>
</table>
p {
font-family: Lato;
}
.employment {
border-collapse: collapse;
width: 100%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
font-family: 'Roboto', 'Helvetica Neue', sans-serif;
font-size: 12px;
font-weight: 500;
margin: 1%;
white-space: nowrap;
}
.employment tr:nth-child(even) {
background: #fafafa;
}
.emp {
width: 50%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
export class AppComponent {
empTabData = [{"employerInfo":[{"key":"UAN","value":"100460235222"}]},{"employerInfo":[{"key":"Matched Name","value":"UAT Test Aadhaar Name"},{"key":"User Id","value":"442ad831-983f-44ca-ac7f-e1851c911fb3"},{"key":"ID","value":"PYBOM00250170000001586"},{"key":"Employer","value":"EMIDS TECHNOLOGIES PVT LTD"},{"key":"Settled","value":"true"}]},{"employerInfo":[{"key":"Matched Name","value":"UAT Test Aadhaar Name"},{"key":"User Id","value":"442ad831-983f-44ca-ac7f-e1851c911fb3"},{"key":"ID","value":"PYKRP17189390000010001"},{"key":"Employer"},{"key":"Settled","value":"false"}]}]
}
Your tbody does not have a display set, and it is not going 100% width.
So try this:
tbody {
width: 100%;
display: table;
}
It's working for me when I change to table-layout: fixed;
tbody{
width: 100%;
display:table;
table-layout: fixed;
}
p {
font-family: Lato;
}
.employment {
border-collapse: collapse;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
font-family: 'Roboto', 'Helvetica Neue', sans-serif;
font-size: 12px;
font-weight: 500;
margin: 1%;
}
.employment tr:nth-child(even) {
background: #fafafa;
}
.emp {
width: 50%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Hope my answer helps you! :)
You can't put <div> as direct child of <table>. https://html.com/tables/ You
have to draw your table starting from something like this.
<table class="employment" *ngFor="let item of empTabData| slice:1">
<tr *ngFor="let i of item.employerInfo | slice:0:(item.employerInfo.length/2)+1">
<td class="emp">
{{i.key}}
</td>
<td class="emp">
{{i.value}}
</td>
</tr>
<tr *ngFor="let i of item.employerInfo | slice:(item.employerInfo.length/2)+1:item.employerInfo.length">
<td class="emp">
{{i.key}}
</td>
<td class="emp">
{{i.value}}
</td>
</tr>
</table>
For example, only by removing divs the size of td.emp (when they have enough space to do so) is 50%.
I'm trying to understand coding of my Wordpress site better, so I set my mind on eliminating as much as plugins as possible, starting with a table plugin which shouldn't be very hard..
I want the table to show in a fixed width (756px) and I want it to scroll if the content is viewed on smaller displays or when the browser window is resized. The goal is to keep the table layout exactly the same.
The problem is that when I specify a width, the table just gets clipped without the option to scroll and when I set the width to 100% the table resizes which I don't want.
I tried reverse engineering the plugin I use, but I guess I don't have the knowledge yet to pull it off.
It's taken a long time now and I just want to move on to the next obstacle:)
Table so far
html:
<div class="tabel">
<table>
<tr>
<th>Eten & Drinken<br /><img src="http://travelaar.nl/wp-content/uploads/2016/12/eten-en-drinken-kraam.png" /></th>
<th>Slapen<br /><img src="http://travelaar.nl/wp-content/uploads/2016/03/slapen.png" /></th>
<th>Vervoer<br /><img src="http://travelaar.nl/wp-content/uploads/2016/12/vervoer-trein-icon.png" /></th>
<th>Excursies<br /><img src="http://travelaar.nl/wp-content/uploads/2016/03/excursies.png" /></th>
<th>Overige<br /><img src="http://travelaar.nl/wp-content/uploads/2016/03/overige.png" /></th>
<th>Totaal</th>
</tr>
<tr>
<td>₱ 35.460,05</td>
<td>₱ 30.484,84</td>
<td>₱ 16.254,76</td>
<td>₱ 5.836,00</td>
<td>₱ 4.086,28</td>
<td>₱ 92.121,93</td>
</tr>
<tr>
<td>€673,74</td>
<td>€579,21</td>
<td>€308,84</td>
<td>€110,88</td>
<td>€77,64</td>
<td>€1.750,32</td>
</tr>
</table>
</div>
css:
.tabel {
white-space: nowrap;
overflow-x: auto;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
background: -webkit-radial-gradient(top left, rgba(185,204,102,0.5), rgba(144,72,138,0.5));
}
table {
border-collapse: collapse;
border: 3px solid black;
table-layout: fixed;
}
tr, th, td {
text-align:center;
border: 1px solid black;
margin: 5px;
white-space: nowrap;
}
th {
vertical-align: top;
}
I got it figured out.. For anyone interested.. here is the result and the answer.
html:
<html>
<head>
<link rel="stylesheet" type="text/css" href="livecss.css">
</head>
<body>
<table class="tabel">
<tr>
<th colspan="6">Indonesië - 29 dagen</th>
</tr>
<tr>
<th>Eten & Drinken<br /><img src="http://travelaar.nl/wp-content/uploads/2016/12/eten-en-drinken-kraam.png" /></th>
<th>Slapen<br /><img src="http://travelaar.nl/wp-content/uploads/2016/03/slapen.png" /></th>
<th>Vervoer<br /><img src="http://travelaar.nl/wp-content/uploads/2016/12/vervoer-trein-icon.png" /></th>
<th>Excursies<br /><img src="http://travelaar.nl/wp-content/uploads/2016/03/excursies.png" /></th>
<th>Overige<br /><img src="http://travelaar.nl/wp-content/uploads/2016/03/overige.png" /></th>
<th>Totaal</th>
</tr>
<tr>
<td>₱ 35.460,05</td>
<td>₱ 30.484,84</td>
<td>₱ 16.254,76</td>
<td>₱ 5.836,-</td>
<td>₱ 4.086,28</td>
<td>₱ 92.121,93</td>
</tr>
<tr>
<td>€ 673,74</td>
<td>€ 579,21</td>
<td>€ 308,84</td>
<td>€ 110,88</td>
<td>€ 77,64</td>
<td>€ 1.750,32</td>
</tr>
</table>
css (including custom scrollbars;))
/*TABEL CSS*/
table {
overflow-x: auto;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
/*background: -webkit-radial-gradient(top left, rgba(185,204,102,0.5), rgba(144,72,138,0.5))*/
border-collapse: collapse;
display: block;
table-layout: fixed;
border-style: hidden;
}
th, td {
border: 1px solid white;
white-space: nowrap;
}
th {
text-align: center;
vertical-align: top;
background-color: #b9cc66;
padding: 5px;
}
td {
text-align: right;
padding: 5px 10px 5px 5px;
background-color: rgba(144,72,138,0.5)
}
.tabel tr > td:last-of-type {
background-color: rgba(144,72,138,0.8)
}
/*SCROLLBAR STYLE*/
::-webkit-scrollbar {
-webkit-appearance: none;
}
::-webkit-scrollbar:vertical {
width: 12px;
}
::-webkit-scrollbar:horizontal {
height: 12px;
}
::-webkit-scrollbar-thumb {
background-color: rgba(0,0,0,0.5);
border-radius: 10px;
border: 2px solid #ffffff;
}
::-webkit-scrollbar-track {
border-radius: 10px;
background-color: rgba(185,204,102,0.2);
}
/*EINDE SCROLLBAR STYLE*/
/*EINDE TABEL CSS*/
I have a table which is used for showing excel-like data. I need to absolutely position two icons in the top center of each row--I want to show edit/delete icons when the use hovers the mouse over any row.
When I tried adding a relative position to the TR and an absolute positioning my inner floating div, the css disregarding the relative positioning of the parent td and simply floated to the top of the screen:
http://jsfiddle.net/85aTs/2/
HTML
<table>
<tr>
<td>
fooasfdasdfasf
</td>
<td>
barasdfasfas
</td>
</tr>
<tr>
<td>
fooasfdasdfasf
</td>
<td>
barasdfasfas
</td>
<div class="absolute">
I should be in a row
</div>
</tr>
</table>
CSS:
table, td{
border: 1px solid #000;
}
tr {
position:relative;
}
.absolute {
position: absolute;
top: 0;
right: 0;
border: 1px solid #000;
background-color: yellow;
}
I am aware that this is not valid html as it is currently setup, but how can I achieve what I want without switching over to divs with table display properties?
Here's what I would do:
See working jsFiddle demo
HTML
<table>
<tr>
<td>
<div class="icons">
<img class="checkmark" />
<img class="crossmark" />
</div>
<table>
<tr>
<td>fooasfdasdfasf</td>
<td>barasdfasfas</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div class="icons">
<img class="checkmark" />
<img class="crossmark" />
</div>
<table>
<tr>
<td>fooasfdasdfasf</td>
<td>barasdfasfas</td>
</tr>
</table>
</td>
</tr>
</table>
CSS
table, td
{
border: 1px solid #000;
}
.icons
{
height: 16px;
text-align: center;
background: #bbb;
}
.checkmark
{
display: inline;
height: 16px;
width: 16px;
border: none;
background: url('http://www.actuary.com/directory/template/default/images/icon_checkmark.gif');
}
.crossmark
{
display: inline;
height: 16px;
width: 16px;
border: none;
background: url('http://researchautism.net/img/rating_icons/crossmark_sm.png');
}
RESULTS