overflow: hidden behind padding - css

Is it possible to define where overflow: hidden begins based on padding?
For example, I currently have a table in which I have a long string. There is padding on the left, but the length of the string exceeds the td, so overtflow hidden is triggered. I would like the overflow: hidden to trigger at the beginning of the padding rather than the end of the td.
Essentially I would like the overflow: hidden to begin at the start of the far right red line.
.order-table td {
padding: 1em 3px;
border-left: #ddd 1px solid;
font-size: 0.9em;
overflow: hidden;
}

Simply wrap your content in another element and apply the overflow: hidden to that instead:
table {
width: 100px;
table-layout:fixed;
}
td {
border: 1px solid red;
padding: 10px;
}
.inner {
border: 1px solid blue;
overflow: hidden;
text-overflow: ellipsis;
}
<table>
<tr>
<td><div class="inner">123456789012345678901234567890</div></td>
</tr>
</table>

Add text-overflow:ellipsis to add an ellipse at the end. Hopefully this fix's your issue.
/*** USELESS STYLES ***/
html,
body {
background: #FFF;
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 14px;
line-height: 1.4em;
}
.element:before {
content: '> ';
}
/*** .USELESS STYLES ***/
.element {
background: #F1F1F1;
color: #555;
padding: 10px 15px;
overflow: hidden;
border: 1px solid #ccc;
margin: 10px;
text-overflow: ellipsis;
white-space: nowrap;
width: 50%;
}
<div class="element" title="This is some text that will need to cut because it will be far to long for users to see but the user should know what it means, and they can even click to find out more about this if your site supports this.">Hover Over Me. This is some text that will need to cut because it will be far to long for users to see but the user should know what it means, and they can even click to find out more about this if your site supports this.</div>

The solution like the following example should work:
div {
border:1px solid #000;
padding:20px;
width:50px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
<div>testtesttesttesttesttest</div>
See on fiddle: https://jsfiddle.net/bm3upfoc/

table {
width: 300px;
table-layout: fixed;
}
td {
border: 1px solid red;
padding: 10px;
overflow: hidden;
}
td span {
float: right;
}
.inner {
border: 1px solid blue;
overflow: hidden;
}
<table>
<tr>
<td>
<span>
something
</span>
</td>
<td>
<span>
1234567890ABCDEFG
</span>
</td>
<td>
<span>
something
</span>
</td>
</tr>
</table>
Wrap the table content to span
<span>
a Very Long line of text and hope this helps
</span>
then add the CSS TD SPAN, float it to right
TD SPAN{
float:right
}

Related

Table cell conundrum: trying to vertically center a link inside a table cell whose entire cell area is link-clickable

As you can see, in order to make the entire table cell link-clickable, I used td a {display: block}. The problem is td a {vertical-align: middle} no longer works with display: block. Not sure how else to center it vertically. Any help would be greatly appreciated.
P.S. I avoided using line-height because my link needs to be multi-line.
table {
width: 300px;
border-collapse: collapse;
}
td {
border: 1px solid #000000;
height: 100px;
vertical-align: middle;
}
td a {
display: block;
height: 100px;
vertical-align: middle !important;
}
<table>
<tr>
<td>TEXT</td>
<td>LINK</td>
</tr>
</table>
You can use an auxiliar span and center it inside the anchor, so its content is free to move and align.
E.g.:
table {
width: 300px;
border-collapse: collapse;
}
td {
border: 1px solid #000000;
height: 100px;
vertical-align: middle;
}
td a {
display: flex;
height: 100%;
}
td a span {
height: fit-content;
align-self: center;
}
<table>
<tr>
<td>TEXT</td>
<td>
<a href="">
<span>
A VERY LONG LINK MAY BE LIKE THIS ONE, I GUES, RIGHT? HERE WE GO :D
</span>
</a>
</td>
</tr>
</table>
Added span in anchor tag and made a CSS change for the output
table {
width: 300px;
border-collapse: collapse;
}
td {
border: 1px solid #000000;
height: 100px;
vertical-align: middle;
}
td a {
display: table;
position: relative;
height: 100%;
width: 100%;
}
span {
display: table-cell;
text-align:center;
vertical-align: middle;
}
<table>
<tr>
<td>TEXT</td>
<td><span>LINK</span></td>
</tr>
</table>

How to add a fixed width of td table

I set a fixed width in td, but it doesn't work when the table is overflow. What I have tried is the below code.
td {
width: 192px;
}
It can resolve by following 2 steps.
1 - On table set width:100%
2 - On td of table use class like this when your data get overflow.
.dataRow
{
word-wrap: break-word;
word-break: break-all;
}
3 - after above 2, you can also set width as per your requirement, if needed.
You can change in css with td { width:20px} or you can change it inline <td style="width:20px">.
This can be achieve using display property.
Check below Snippet.
.wrapper {
width: 180px;
border: 1px solid #000;
}
.table-scroll {
width: 100%;
table-layout: fixed;
}
.table-scroll tbody {
display: block;
overflow: scroll;
}
.table-data {
border: 1px solid #0F0;
}
.table-detail {
border: 1px solid #F00;
}
td.first {
width: 200px;
display: inline-block;
}
<div class="wrapper">
<table class="table-scroll table-data">
<tbody>
<tr>
<td class="first">HEAD1</td>
<td>HEAD2</td>
<td>HEAD3</td>
<td>HEAD4</td>
</tr>
</tbody>
</table>
</div>

navigation bar links move when hover

In my html page I have the following for the hover action on the navigation links.
<td class="menuNormal"
onmouseover="expand(this);"
onmouseout="collapse(this);"
width="130"
align="left">
<p><b>Vida de Mulher</b></p>
<div class="menuNormal">
<table class="menu" width="130">
<tr>
<!-- ... -->
And this is the css style sheet which is used for the hover action:
table.navbar {
font-size: 12pt;
margin: 0px;
padding: 0px;
border: 0px;
}
table.menu {
font-size: 11pt;
margin: 5px;
padding: 0px;
}
td.menuNormal {
padding: 0px;
color: #003399;
vertical-align: top;
background-color: #f6f6f6;
}
td.menuHover {
padding: 0px;
color: #003399;
width: 112px;
vertical-align: top;
background-color: lightblue;
}
This may be caused by a :hover effect in your css, or maybe removing the width of your td class .menuNormal in your html code will remove this moving effect, in last case if none of these works I suggest adding the same width to td.menuHover assuming this class was created for some hover effect on your td
td.menuHover {
padding: 0px;
color: #003399;
width: 130px; /* changing this value for the same as .menuNormal */
vertical-align: top;
background-color: lightblue;
}

Needs use right "text-overflow" when "direction" is set to "rtl"

I need to put "..." in the front of text and show only last part of it, when it fills div.
And do nothing when it is normal
<span class="file-upload-status" style="max-width:200px">
C:\fakepath\996571_1398802860346752_2094565473_n.jpg
</span>
<br/>
<span class="file-upload-status" style="max-width:200px">
C:\fakepath\1.jpg
</span>
Here is what i have : http://jsfiddle.net/CBUH4/5/
Here is what i need :
Is it possible to do by Css, without using JavaScript or jQuery.
Maybe something like this: http://jsfiddle.net/CBUH4/8/
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
This is the closest solution I could have got using just css. Still it has a drawback that we need to use multiple .'s which are approximately equal to the width of the span element.
Fiddle
HTML
<span class="file-upload-status ellipsis" style="max-width:200px">
C:\fakepath\996571_1398802860346752_2094565473_n.jpg
</span>
<br/>
<span class="file-upload-status" style="max-width:200px">
C:\fakepath\1.jpg
</span>
CSS
.file-upload-status {
font-weight: bold;
font-size: 16px;
color: #888;
background: #fff;
border-radius: 7px;
height: 27px;
border: 1px solid #ccc;
padding-left: 5px;
padding-right: 5px;
white-space: nowrap;
overflow: hidden;
direction: rtl;
display:inline-block;
width: 200px;
position: relative;
}
.file-upload-status:after {
content:".................................";
color: white;
position: relative;
background-color: white;
z-index: 2;
}
.file-upload-status:before {
content:"...";
position:absolute;
background-color: white;
left: 0px;
top: 0px;
z-index: 1;
}
Suggestion: Give as much dots as possible :D

css: ie shifts button's text value and background

I've got a submit button in a list:
<ul>
<li><input type="submit" value="Pls don't shift" /></li>
</ul>
The li and the input have different backgrounds, and these should be positionable.
The input should have dynamic width (depending on the value).
The input's value should be almost at the input's bottom.
These things reduce the number of opportunities to solve the problem.
And the problem exactly is: IE8 and IE9 shift the text of value, and IE8 shifts the background too.
I've tried to solve it and made this css (this is only a 'debug-css'):
li {
display: block;
width: auto;
border: 1px solid red;
padding: 0;
margin: 0;
float: left;
overflow: hidden;
}
input,
input:active:hover {
display: block;
background: url(tools-48x48.png) no-repeat center center;
width: auto;
height: 60px;
border: 1px solid transparent;
outline: none;
color: #fff;
text-align: center;
position: relative;
overflow: visble;
padding: 0 10px;
margin: 2px;
}
input:active:hover {
border: 1px solid red;
}
And the most interesting thing is: Now if I click on the button's text value, then it makes the same bad shift, but if I click eslewhere (on the button, but not on the text value) then it works.
That was the point when I've minded to write here.
How to disable submit buttons :active state in IE?
Thank you!
I have tested this in IE9 and when I remove several styles that "aren't" used the input text doesn't shift when you click on it.
removed styles:
li {
width: auto;
border: 1px solid red;
padding: 0;
margin: 0;
overflow: hidden;
}
input,
input:active:hover{
background: url(tools-48x48.png) no-repeat center center;
outline:none;
}
and added the styles
input,
input:active:hover{
position: relative;
overflow: visible;
}
See my Fiddle for more details here: http://jsfiddle.net/f67Vw/4/
A good other option seems to be to replace it with a carefully styled a element.
HTML
<ul>
<li>
Doesn't shift
</li>
</ul>
CSS
.button {
display: block;
width: auto;
height: 19px;
border: 1px solid transparent;
color: #000;
text-align: center;
padding: 20px 10px;
margin: 2px;
text-decoration:none;
}
Again see my Fiddle for more details here: http://jsfiddle.net/f67Vw/4/

Resources