Align Font Awesome icon vertically centred and to left of table - css

I am trying to position a font-awesome icon to the left of a table element, such that it is vertically centred against the table.
This is what I have at the moment:
HTML
<div class="dates">
<i class="fa fa-calendar fa-4x" aria-hidden="true"></i>
<table>
<tbody>
<tr>
<td>24th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>25th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>26th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>27th Jul 2018</td>
<td>1PM / 7PM</td>
</tr>
</tbody>
</table>
</div>
CSS
.dates {
border: 3px solid black;
display: inline-block;
padding: 8px 0;
border-radius: 10px;
background-color: white;
border-color: grey;
.fa {
vertical-align: middle;
}
table {
display: inline-block;
td {
font-weight: bold;
margin: 0;
padding: 0 10px;
}
}
}
And it's giving me this result:

Add display: inline-block and vertical-align: middle to both the icon and table, like so:
(For the purposes of the demo I unnested your Sass into normal CSS.)
.dates {
border: 3px solid black;
display: inline-block;
padding: 8px 0;
border-radius: 10px;
background-color: white;
border-color: grey;
}
.fa {
display: inline-block;
vertical-align: middle;
}
table {
display: inline-block;
vertical-align: middle;
}
td {
font-weight: bold;
margin: 0;
padding: 0 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="dates">
<i class="fa fa-calendar fa-4x" aria-hidden="true"></i>
<table>
<tbody>
<tr>
<td>24th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>25th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>26th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>27th Jul 2018</td>
<td>1PM / 7PM</td>
</tr>
</tbody>
</table>
</div>

Related

Attach the css arrow to the top of a css border

This would be really easy using negative margins, but I can't use them inside a <table>. Been at this for hours last night and this morning. Already googled different types of navs and there's nothing like this.
How do I make the CSS arrow stick to the top and bottom of the vertical line? https://codepen.io/TylerL-uxai/pen/ZqYNjw
td {
padding-top: 10px;
padding-bottom: 10px;
}
.active {
font-weight: bold;
}
table {
border-collapse: collapse;
}
.right{
text-align: right;
border-right: 1px solid black;
}
.v {
text-align: right;
}
i {
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
}
.down {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
.up {
transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
}
.dot {
height: 10px;
width: 10px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
<div class="menu">
<table>
<tr>
<td class="v">
<i class="arrow up"></i>
</td>
<td>
Abstract
</td>
</tr>
<tr>
<td class="right">
Why
</td>
</tr>
<tr>
<td class="right">
<div class="active">Home</div>
</td>
<td><span class="dot"></span> <small> You are here.</small></td>
</tr>
<tr>
<td class="right">
Examples
</td>
</tr>
<tr>
<td class="right">
Process
</td>
</tr>
<tr>
<td class="right">
Tools
</td>
</tr>
<tr>
<td class="v"><i class="down"></i></td>
<td style="padding-left: 10px;">
Concrete
</td>
</tr>
</table>
</div>
Position relative and then use top & right negatives
.v {
position: relative;
right:-6px;
top: -15px;
text-align: right;
}

Fixed table width and overflow:auto. How get it to scroll?

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*/

HTML table - remove cellspacing/border from a particular cell

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.

Element appears in the same line

I have to make in html a calendar. I want to make this with tables.
All I want is the "2" to be in the same line with the others elements(3,4,5...etc).
Code:
<table class="calendar-program col-md-12">
<thead>
<tr>
<th>L</th>
<th>M</th>
<th>M</th>
<th>J</th>
<th>V</th>
<th>S</th>
<th>D</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2
<div class="clearfix"></div>
<small class="event-calendar">1 event</small>
</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
</tbody>
</table>
CSS:
table.calendar-program >tbody> tr>td{
width: 14%;
border: 1px solid #000;
text-align: center;
}
small.event-calendar{
clear: both;
color: #000!important;
font-size: 10px;
}
Demo
You can add vertical-align: top; to the CSS for your td.
That will give you a layout like this:
You can make a nicer, more controlled result with positioning, like this: http://jsfiddle.net/B32Cc/
table.calendar-program >tbody> tr>td{
width: 14%;
border: 1px solid #000;
text-align: center;
position: relative;
padding: 10px 15px;
}
small.event-calendar{
clear: both;
color: #000!important;
font-size: 10px;
position: absolute;
bottom: 0px;
left: 0;
width: 100%;
}

Position a div absolutely inside a tr

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

Resources