Hide a <td> behind another <td> inside a <table> - html

I have a table which looks something like the following.
<table>
<tr>
<td class="selected plus"><a>+</a></td>
<td><a class="minus">-</a></td>
</tr>
</table>
I want that only the selected td is visible. My restrictions are to achieve this only through CSS. I am not able to alter the HTML or inject some kind of JavaScript.
This is what I come up with yet:
position the selected td over the other
expand the selected td to "displace" the other
hide the not selected td
Unfortunately I was not successful with neither of those ideas, so do you guys have any idea how to achieve this?
Here is a jsfiddle to play around with: http://jsfiddle.net/u6n7r/6/
I would be happy with a cross browser solution, but IE9 support is mandatory.

Just hide the <td/> with display: none:
td:not(.selected) { display: none; }
Here is an Update to your Fiddle

Position the table relative. Position the td's absolute, with top:0 and left: 0. Give the td's a z-index of 10. Give .selected a z-index of 11.
.selected {
background-color: green;
z-index: 11;
}
.plus {
}
.minus {
}
td {
width: 30px;
height: 30px;
border: 3px solid red;
background-color: silver;
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
table {
border: 3px solid blue;
width: 72px;
height: 36px;
position: relative;
}

Related

How to add single short line, '|' as column separator in html table

I have a problem that has been confusing me for the past day. I have to create a table like the attached image. I have to follow the CSS rules and however I cannot figure out how to draw the single black bar in between EDIT and DELETE. I tried the | however it does not look quite correct. I did a colspan=2 for the header and just got the grey bar per the CSS between EDIT and DELETE.
I appreciate any suggestions that you may have.
I would approach it using a pseudo element like this:
button {
border: 0;
background: transparent;
position: relative;
padding: 0;
}
button + button {
margin-left: 10px;
padding-left: 10px;
}
button + button:after {
content: '';
width: 1px;
height: 10px;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
background: black;
}
<button>Edit</button>
<button>Delete</button>
Addin this to the "edit" button in css:
display: block;
Padding: 0 10px;
Border-right: 1px solid black;
td:after{
content:"|";
margin-left:5px; /*To make it look good*/
}
do this

How put some horizontal offset to an element bottom border with CSS?

I use bottom-border on some a element, and I want to add some horizontal offset to the border.
What I have now:
Link very cool name
-------------------
What I want:
Link very cool name
----------------
How can I archive this? Only using an a element.
A pseudo-element is ideal here which can be styled in any fashion you want, color, width & height...even position below the link text.
a {
position: relative;
text-decoration: none;
}
a::after {
content: "";
position: absolute;
top: 100%;
right: 0;
width: 75%;
height: 2px;
background: orange;
}
Long stretch of text
You can try this:
a{
text-decoration: none;
display:inline-block;
}
a:after{
content: "";
border-bottom: dotted 2px red;
width: 70%;
float: right;
padding-top: 5px;
}
https://jsfiddle.net/9xc0x58c/1/
You could use a pseudo element ie :after element for this and abs pos it, 1px high background colour and width of you chosen link length etc.
Would that be the required result? Not sure the requirement as to why you would want this but it should achieve the required result.
you can use span
HTML
Link <span class="un">very cool name</span>
CSS
.un{
border-bottom: dotted 2px red;
}

Positioning of pseudo-elements like :after in Firefox

Consider the following HTML:
<table>
<thead>
<tr>
<th class="title">Test title</th>
</tr>
</thead>
</table>
And the following CSS:
table {
width: 400px;
border: 1px solid #ccc;
}
th.title {
position: relative;
text-align: center;
}
th.title::after {
position: absolute;
right: 5px;
content: '>';
}
See the JSFiddle http://jsfiddle.net/63EZB/1.
What I want is the greater than sign to appear on the right side of the th. The code above works both in Chrome and IE8+, but not in Firefox (28). Firefox positions the sign absolutely on the window's right, like the relative position of the th element isn't considered.
What's going wrong?
Looking for something like this Link
CSS:
th.title::after {
margin-right: 5px;
float:right;
content:'>';
}
Try with theses rules :
th.title:after {
position:relative;
float:right;
right: 5px;
content: '>';
}
As I understand it (I rarely work with tables) table elements don't mix well with absolute or relative positioning.
I would simply put a holding div inside the th and give that the position relative and the pseudo element.
This could also give you some ideas: http://css-tricks.com/absolutely-position-element-within-a-table-cell/

Html non straight border liner for tables

I want to make a table via Html/Css (Javascript if needed) which basically looks like this:
As you can see there every row in this table has a bottom border, which starts above an image in the table, and then goes down to the other columns.
Is there any way to do this? (Maybe with a transparent image?)
You can use a psudo element with a rotation to solve this:
Check out this jsfiddle
http://jsfiddle.net/zRMLr/
You will likely have to play with the numbers a lot to get it to work with whatever you want.
what I used in this demo (no images) BUT only works for IE9+
html:
<table>
<tr><td><div></div></td><td></td><td>Some sort of text</td></tr>
<tr><td><div></div></td><td></td><td>Some sort of text</td></tr>
<tr><td><div></div></td><td></td><td>Some sort of text</td></tr>
</table>
css:
table {
width: 400px;
}
td:first-child {
border-top: 1px solid black;
width: 20px;
}
td:first-child:after {
content: '';
border-top: 1px solid black;
display: block;
width: 28px;
height: 1px;
float: left;
position:relative;
top: -5px;
left: 24px;
transform:rotate(45deg);
-ms-transform:rotate(45deg); /* IE 9 */
-moz-transform:rotate(45deg); /* Firefox */
-webkit-transform:rotate(45deg); /* Safari and Chrome */
-o-transform:rotate(45deg); /* Opera */
}
td:first-child div {
width: 10px;
height: 10px;
background-color: red;
}
td:nth-child(2) {
width: 14px;
}
td:last-child {
border-bottom: 1px solid black;
}
What you may do to achieve the desired effect is:
Create a div with a left/right border
Rotate using CSS3 rules the div to give this effect
Or
create a div with a left/right border
use border radius to have the desired effect
I hope this helps, if you would like I can bring some sample of code for you

CSS: Labels in table columns

BACKGROUND:
I would like to have small labels in columns of a table.
I'm using some implemented parts of HTML5/CSS3 in my project, and this section specifically is for mobile devices. While both facts are not necessarily relevant, the bottom line is that I don't have to support Internet Explorer or even Firefox for that matter (just WebKit).
THE PROBLEM
With my current CSS approach, the vertical padding of the cell comes from the <span> element (set to display: block with top/bottom margins), which contains the "value" of the column. As a result there's no padding when the <span> is empty or missing (no value) and the label is not in place.
The "full" coulmns should give you the idea of where I want the labels to be, even if there's no value, and the <span> is not there.
I realize that I could use "non-breaking-space", but I would really like to avoid it.
I wonder if any of you have a fix / better way to do this? current code is below.
<!DOCTYPE html>
<html lang="en">
<head>
<title>ah</title>
<style>
body {
width: 320px;
}
/* TABLE */
table { width: 100%; border-collapse: collapse; font-family: arial; }
th, td { border: 1px solid #ccc; border-width: 0px 0px 1px 1px; }
th:last-child, td:last-child { border-right-width: 1px; }
tr:first-child th { border-top-width: 1px; background: #efefef; }
/* RELEVANT STUFF */
td {
padding: 3px;
}
td sup {
display: block;
}
td span {
display: block;
margin: 3px 0px;
text-align: center;
}
</style>
</head>
<body>
<table>
<tr>
<th colspan="3">something</th>
</tr>
<tr>
<td><sup>some label</sup><span>any content</span></td>
<td><sup>some label</sup><span>any content</span></td>
<td><sup>some label</sup><span></span></td><!-- No content, just a label -->
</tr>
</table>
</body>
</html>
As above, you can use:
td {
padding: 3px;
vertical-align:top;
}
If you wanted to retain the padding exactly, even on the invisible elements, you can force the hasLayout attribute on the empty span using:
td {
padding: 3px;
vertical-align:top;
}
td sup {
display: block;
}
td span {
display: inline-block;
margin: 3px 0px;
text-align: center;
width:100%;
}
The inline-block technique is discussed extensively at Drawing empty inline boxes in CSS?