Position a div absolutely inside a tr - 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

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

Size single td in single row

I'm trying to size a single td in a table row.
<table>
<tr>
<td>
<span>1</span>
</td>
<td marked="true"> <!-- Should be 80px height and width -->
<span>2</span>
</td>
<td>
<span>3</span>
</td>
</tr>
</table>
Now all my td's have 60px height and the width is set through js.
I want to set the marked="true" td to 80px height and width and all other td's should stay at 60px height.
I'm able to resize the marked="true" td but the problem is, that all other tds heights are resized too and this should not happen.
I tried it with the td height and width attributes, with css and tried to size the span, but none of them work.
Is this somehow possible?
Help would be greatly appreciated.
EDIT
This is how it looks like now:
It is a navigable days table.
The blue bordered td should be 80px height and width.
And the others shoult be vertically aligned to it.
I think it's best not to use a table.
Instead I would use something like the following HTML:
<div id="dayList">
<div>7</div>
<div>8</div>
<div data-marked="true">9</div>
<div class="Weekend">10</div>
<div class="Weekend">11</div>
</div>
and the following CSS:
#dayList {
display: flex;
flex-flow: row nowrap;
align-items: center;
align-content: center;
}
#dayList > div {
flex: 0 0 60px;
margin: 1px;
border: 1px solid #CCC;
width: 60px;
height: 60px;
background-color: #EEE;
text-align: center;
line-height: 60px;
}
#dayList > div.Weekend {
background-color: #CCC;
}
#dayList > div[data-marked=true] {
flex: 0 0 80px;
border: 1px solid #00F;
width: 80px;
height: 80px;
line-height: 80px;
}
It would look like this:
Add a class to td.
.big {
height: 80px;
width: 80px;
}
<table>
<tr>
<td>
<span>1</span>
</td>
<td class="big" marked="true">
<!-- Should be 80px height and width -->
<span>1</span>
</td>
<td>
<span>1</span>
</td>
</tr>
</table>
Maybe this:
<table>
<tr>
<td></td>
<td rowspan="3" marked="true" class="marked" width="80" height="80">test</td>
<td></td>
</tr>
<tr>
<td>
<span>1</span>
</td>
<td>
<span>1</span>
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
CSS:
td {
border: 1px solid green;
}
It seems this works as expected, added class .narrow:
.narrow {
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
https://jsfiddle.net/rinatoptimus/4hw1a8f3/

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.

CSS Float fails for HTML5 Input Elements

I'm running into an issue when using HTML5 form input types (number, date, email, etc) with the CSS float property. I'm trying to float these to the right, but they are not honoring that setting.
Here's a snippit where I put the CSS inline during testing:
<div class="center" style="width: 100%">
...
<div style="width: 90%" class="textfont">
...
<table style="width:100%;">
<thead>
<tr class="tableHeading">
<td style="width: 50%; text-align: center;">
Unit Types
</td>
<td style="text-align: center;">
Number of Units
</td>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 1px;">
Single-Family Detached
</td>
<td>
<input type="number" name="txtDetached" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td style="height: 32px">
Townhouse, Row, or Cluster
</td>
<td style="height: 32px">
<input type="number" name="txtCuster" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td>
Garden
</td>
<td>
<input type="number" name="txtGarden" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td style="height: 43px">
Mid-rise (3-5)
</td>
<td style="height: 43px">
<input type="number" name="txtMidrise" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td>
High-rise (6+)
</td>
<td>
<input type="number" name="txtHighRide" style="width:25%; float: right" />
</td>
</tr>
<tr>
<td>
Other
</td>
<td>
<input type="text" name="txtOther" style="width: 80%; float: right;" />
</td>
</tr>
</tbody>
</table>
...
</div>
...
</div>
Yes, I know tables are frowned upon...
Here's the overall CSS:
.Header
{
font-size: 30px;
font-family: Cambria;
color: White;
background: #254117;
text-align: center;
font-weight: bold;
width: 90%;
}
.subHeading
{
font-family: Arial;
font-size: 11px;
text-align: left;
}
.container
{
display: table;
width: 90%;
border-collapse: collapse;
}
.heading
{
font-weight: bold;
display: table-row;
background-color: #C91622;
text-align: center;
line-height: 25px;
font-size: 14px;
font-family: georgia;
color: #fff;
}
.table-row
{
display: table-row;
text-align: center;
}
.col
{
display: table-cell;
border: 1px solid #CCC;
}
.tableHeading
{
font-family: Arial;
background: #99C68E;
font-size: 18px;
text-align: left;
}
.textfont
{
font-size: 15px;
font-family: Arial;
text-align: left;
}
input[type=text]
{
width: 100%;
height: 22px;
}
textarea
{
width: 98%;
}
table
{
border-collapse: collapse;
border: 1px solid black;
border-spacing: 10px;
}
tr
{
border-collapse: collapse;
border: 1px solid black;
}
td, th
{
padding: 5px;
}
.center
{
margin-left: auto;
margin-right: auto;
}
Here's what this displays:
As you can see the input element with type="text" works without an issue, however when type="number" it remains at the default, left justified.
This behavior exists in IE 10, FireFox, and Chrome.
I discovered the workaround is to wrap the HTML5 input types in a div and then set the CSS to float the div right, and then this works without issue. I had issues finding information for this on the net, but is this a known issue? Is the workaround actually the proper way of handling this?
EDIT: Added full CSS (minus stuff I moved inline for testing). Added entire table and the div's they are wrapped in. If I copy all of this to jsFiddle it works properly, so I'm obviously doing something wrong here...
OK, the problem related to floating elements inside <td>, use text-align can fix it.
<td style="text-align:right;">
...
</td>
More can be read here DIV in <td> float right

Show parent and child ine separate box using CSS

Please have a look in the following URL:
"http://jsfiddle.net/7rsx0r4h/"
I want the output like the output table with border and should be look like separate box but don't want to change my html (div layout). Also every box i require some space then another box start.
Thanks,
Manish
demo - http://jsfiddle.net/victor_007/7rsx0r4h/1/
added outline for the first div
change body to the parent id or class
body > div {
outline:1px solid #4679bd;
}
changed border color to white so that it looks like empty space
div div {
border-top: 2px solid white;
}
body > div {
outline: 1px solid #4679bd;
}
div {
width: 496px;
border: 2px solid white;
border-top: 0;
color: #fff;
text-align: center;
font-size: 120%;
background: #4679bd;
}
div div {
font-size: 100%;
width: auto;
border: 0;
border-top: 2px solid white;
line-height: 250%;
}
<p>Divs:</p>
<div>
<div>1
<div>1.1
<div>1.2
<div>1.2.1</div>
</div>
</div>
</div>
<div>2
<div>2.1
<div>2.2
<div>2.2.1</div>
</div>
</div>
</div>
<div>3</div>
<div>4</div>
</div>
<br />
<p>Table:</p>
<table border="1px" width="500px">
<tr>
<td>1</td>
</tr>
<tr>
<td>1.1</td>
</tr>
<tr>
<td>1.2</td>
</tr>
<tr>
<td>1.2.1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>3.1</td>
</tr>
</table>

Resources