CSS Table to read left to right - css

I do not have control over the markup on this table, only the CSS.
I'm looking to make the table read from left to right instead of the vertical.
http://jsbin.com/oXOYayA/1/edit
Any thoughts would be greatly appreciated. Thanks.

This works.
FIDDLE
body {
-webkit-transform: rotate(90deg);
}
table {
width: 100%;
border: none;
padding: 0;
margin-top: 100px;
-webkit-transform: scaleY(-1);
}
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
-webkit-transform: scaleY(-1);
}
table tr:first-child td {
background: #e9e9e9;
}
table tr td {
padding: 10px 5px 10px 5px;
text-align: center;
border: 1px solid #43447b;
-webkit-transform: rotate(-90deg);
height:60px;
}
Just make sure you replace body with whatever container holds the table to be flipped.

I'm not sure what you're asking. But you want the <th> on the bottom and <td> at the top?
You can mirror the table on the Y-axis and reset the mirror on the td so the text isn't mirrored:
table {
width: 100%;
border: none;
padding: 0;
margin-top: 28px;
-moz-transform: scaleY(-1); /* Gecko */
-o-transform: scaleY(-1); /* Operah */
-webkit-transform: scaleY(-1); /* webkit */
transform: scaleY(-1); /* standard */
}
table tr td {
padding: 10px 5px 10px 5px;
text-align: center;
border: 1px solid #43447b;
-moz-transform: scaleY(-1); /* Gecko */
-o-transform: scaleY(-1); /* Operah */
-webkit-transform: scaleY(-1); /* webkit */
transform: scaleY(-1); /* standard */
}
jsBin

Does it have to work in older browsers? For newer browsers I'd recommend rotating the table 90deg counter-clockwise using CSS3 transforms and then rotate the cells back the other way.
http://jsbin.com/oXOYayA/5/edit
Works best if all cells are square (that's why i set explict width/height on the TDs
EDIT: Actually, if you combine my answer with nkmols it can be done: http://jsbin.com/oXOYayA/7/edit
The trick is to combine the transforms
transform: rotate(-90deg) scaleX(-1);
It rotates part of the table out of view but you can fix that easily enough by setting a pivot point for the transform.

I know you said you can't change the markup but I have used < thead > < tbody > tags. In your case, just use class names to replace the thead and tbody tags.
Fiddle: http://jsfiddle.net/jennift/aCs7c/
For the table:
<table border="0">
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
<th>Head 4</th>
<th>Head 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>188</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>211</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
And the css:
table {
border-collapse: collapse;
border-spacing: 0;
position: relative;
}
thead {
display: block;
float: left;
}
tbody {
display: block;
position: relative;
overflow-x: auto;
white-space: nowrap;
}
thead tr {
display: block;
}
th {
display: block;
text-align: right;
border:1px solid #000;
}
tbody tr {
display:inline-block;
vertical-align: top;
float:left;
}
td {
display: block;
text-align: left;
border:1px solid #000;
}
/*fix your borders*/
you can also refer to http://elvery.net/demo/responsive-tables/

Related

CSS for Table Header with auto-sized trailing underline

Using only HTML and CSS,
I wish to have a table like the following:
Header1 Header2
-------------- --------------------
L1Col1 content L1Col2 wider content
L2Col1 datum L2Col2 datum2
Where the underline automatically sizes to the
table column width.
Help!
Try this:
CSS:
.sample-table {
width: 50%;
text-align: left;
border-spacing: 25px 0;
}
.sample-table th {
border-bottom: 1px dashed #000;
}
.sample-table td,
.sample-table th {
padding: 3px;
}
HTML:
<table class="sample-table">
<tr>
<th>Header1</th>
<th>Header2</th>
</tr>
<tr>
<td>L1Col1 content</td>
<td>L1Col2 wider content</td>
</tr>
<tr>
<td>L2Col1 datum</td>
<td>L2Col2 datum2</td>
</tr>
</table>
Azu,
Thanks for your answer.
The "border-spacing" usage was completely enlightening to me.
I modified the CSS to the following:
.sample-table {
text-align: left;
border-spacing: 25px 0;
}
.sample-table th {
border-bottom: 2px solid #000;
}
.sample-table td,
.sample-table th {
padding: 3px 0px;
}
This gives me exactly what I wanted.

How to place text on top of two table cells?

Lets say we have this table:
<table>
<tr>
<td width="50px">Text crossing two td´s</td>
<td width="50px"></td>
</tr>
</table>
How can the text be on top of the two td´s and follow the size of the tr?
https://jsfiddle.net/roj7w1t4/
Is it possible?
EDIT
I need the borders to stay visible. Therefore i cannot use colspan!
Is it possible to create a span and put it over the td´s?
To make more sense what i am trying to do.. this is a small example of my application: What printable element is better to use than linear-gradient?
THE ELEMENT
<div class="elementsDiv ui-draggable ui-draggable-handle" id="29065-1_105" data-weight="938" data-nr="105" style="width: 159.5px; height: 20px; position: absolute; left: 108px; top: 27.1875px;"><table style="height: 100%;"><tbody><tr style="border 1px solid black;"><td style="width: 34.2px; border-right: 1px dotted black;">105</td><td style="width: 91px; border-right: 1px dotted black;"></td><td></td></tr></tbody></table></div>
The only way I can image doing this is placing an element outside the table and having a container around the table and the element. Then placing the element using position absolute on top of the table.
div {
width: 200px;
position: relative;
}
table {
width: 200px;
}
td {
border: 1px solid red;
height: 40px;
}
span {
position: absolute;
padding: 2px;
z-index: 99;
}
<div>
<span>Lorem ipsum dolor sit amet</span>
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
How about changing your html layout? Try to use after pseudo element and position:absolute. This technique saves me in a lot of situation and it's very strong, I think.
div {
border: 1px solid green;
padding: 2px;
position: relative;
width: 150px;
}
div:after {
background: green;
bottom: 0;
content: '';
display: block;
left: 50%;
position: absolute;
top: 0;
transform: translateX(-50%);
width: 1px;
}
<div>
This text should cross two td´s
</div>
table {
border: 1px solid black;
}
td {
border: 1px solid red;
}
th {
text-align:center;
}
<table>
<tr>
<th colspan="2">Monthly Savings</th>
</tr>
<tr>
<td width="50px">This text should cross two td´s</td>
<td width="50px"></td>
</tr>
</table>
You can include the border will be visible.
All the best. For any query please comment.

HTML Table of Acronyms - show meaning on mouseover

I have a HTML Table with 2 columns and about 80 rows, which contains Acronyms, and their meanings.
Is there a (CSS?) way to display just the first row of the table, and have the meaning (i.e. it's accompanying td in the same tr) come up in some sort of box on mouseover?
This question has been asked before, but yes. You can.
JSfiddle
CSS:
.meaning {
display:none;
}
.Acronym:hover + .meaning {
display:unset;
}
HTML:
<table>
<tbody>
<tr><td class="Acronym">Foo</td><td class="meaning">bar</td></tr>
<tr><td class="Acronym">Foo2</td><td class="meaning">bar2</td></tr>
</tbody>
</table>
This is possible with only css using the :hover selector.
Here is an example of a cell with a tooltip, each .cell can be a <td> in a table.
Codepen
html
<span class="cell">
acr.
<div class="tooltip">Acronym</div>
</span>
css
.cell {
border: 1px solid black;
padding: 5px 10px;
}
.cell .tooltip {
position: absolute;
opacity: 0;
transition: opacity 250ms;
border: 1px solid grey;
background-color: white;
padding: 2px;
}
.cell:hover .tooltip {
display: block;
opacity: 1;
}

100% height pseudo element on a table cell in IE

I am encountering an issue in IE9,10,11 where an ::after pseudo element will not fill 100% of the height of it's td parent.
If the first column in the second row had two lines of text, the pseudo element would fill the full height with no problem. So, I figured that the issue was happening because the td was not filling the height of the tr but that isn't the case.
The first screenshot is Chrome and the second is IE9
HTML
<table>
<tr>
<td>Two<br/>Lines</td>
<td>Two<br/>Lines</td>
</tr>
<tr>
<td>One Line</td>
<td>Two <br/>Lines</td>
</tr>
</table>
CSS
table td {
border-bottom: 1px solid;
}
table td:first-child {
position: relative;
}
table td:first-child::after {
position: absolute;
top: 0;
right: 0;
content: '';
width: 2px;
height: 100%;
display: block;
background-color: orange;
}
Codepen: http://codepen.io/cbier/full/BjpaqB/
P.S. I am using an ::after pseudo-element instead of borders for a special reason and it is a requirement
Thanks!
May be using a single pseudo element for the whole table ?
table {
overflow: hidden;
}
table td {
border-bottom: 1px solid;
}
table tr:first-child td:first-child {
position: relative;
}
table tr:first-child td:first-child:after {
position: absolute;
top: 0;
right: 0;
content: '';
width: 2px;
height: 1000px;
display: block;
background-color: orange;
}
<table>
<tr>
<td>Two<br/>Lines</td>
<td>Two<br/>Lines</td>
</tr>
<tr>
<td>One Line</td>
<td>Two <br/>Lines</td>
</tr>
</table>
An alternate way, with background : linear-gradient
table td {
border-bottom: 1px solid;
}
table td:first-child {
background-image: linear-gradient(270deg, orange 3px, transparent 3px);
}
<table>
<tr>
<td>Two<br/>Lines</td>
<td>Two<br/>Lines</td>
</tr>
<tr>
<td>One Line</td>
<td>Two <br/>Lines</td>
</tr>
</table>
You can use following code for it:
table td:first-child::after {
position: absolute;
top: 0;
right: 0;
content: '';
width: 2px;
height: 45px;
display: block;
background-color: orange;
}
it is giving same output in chromeas well as IE 9

CSS3 diagonal rotate text-align

fiddle: https://jsfiddle.net/mj3ez7cL/
How do I make the diagonal labels text-align: right no matter how long the label is the last letter should be tied to the bottom of the 'th'-element, I have tried to add more negative margin-top, but that only solves the overflow issue, also I wouldn't be sure how long a label could be so it needs to be a dynamic solution
th[class='special'] span {
margin-top: -40px; // no good, we don't know how
// long a label could be and this doesnt align the
// text to the right (th bottom)
}
You can try this, using absolute position on the span, and set the text direction to "right-to-left", so it always renders from the bottom/right.
JsFiddle Demo
th[class='special'] {
width: 40px;
position: relative;
}
th[class='special'] span {
position: absolute;
bottom: 0;
direction: rtl;
}
* {
margin: 0;
padding: 0;
text-align: left;
}
table {
margin-top: 50px;
width: 100%;
}
table tr, table th, table td {
border: 1px solid #e1e1e1;
}
th[class='special'] {
width: 40px;
position: relative;
}
th[class='special'] span {
/* margin-top: -10px; */
/* margin-left: -10px; */
position:absolute;
bottom:0;
direction: rtl;
width: 28px;
white-space: nowrap;
display: block;
/*Firefox*/
-moz-transform: rotate(45deg);
/*Safari*/
-webkit-transform: rotate(45deg);
/*Opera*/
-o-transform: rotate(45deg);
/*IE*/
writing-mode: tb-rl;
filter: flipv fliph;
}
<table>
<thead>
<tr>
<th>Hello</th>
<th class="special"><span>Foo</span></th>
<th class="special"><span>Foobar</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>World</td>
<td>Yes</td>
<td>No</td>
</tr>
</tbody>
</table>

Resources