How to Use CSS to Show on Hover Tool-Tips Using the Same Text Which Is Shortend With Ellipses

How do I use css to show on hover tool-tips using the same text which is shortend with ellipses?

Can't you just use the title attribute of the span???

<style>.don_single_donatori {  width: 250px;  min-height: 310px;}
.overview span { text-overflow: ellipsis; width: 100px; white-space: nowrap; overflow: hidden; display: inline-block;}
.overview em { font-style: normal; color: #000; float: right;}</style><div class="don_single_donatori"> <div class="viewport"> <div class="overview"> <p><span title="This is my full name which should be shortend"> This is my full name which should be shortend </span><em>2.000,00 EUR</em></p> <p><span>Anonymous</span><em>2.000,00 EUR</em></p> <p><span>Anonymous</span><em>500,00 EUR</em></p> <p><span title="This is another long name that needs shortening"> This is another long name that needs shortening </span><em>2.000,00 EUR</em></p> <p>Anonymous<em>2.000,00 EUR</em></p> </div> </div></div>

Making a simple tooltip with only HTML and CSS

I found a method to make a very lightweight tooltip with no JS!

.ht:hover .tooltip {
display:block;
}

.tooltip {
display: none;
color: red;
margin-left: 28px; /* moves the tooltip to the right */
margin-top: 15px; /* moves it down */
position: absolute;
z-index: 1000;
}
<table>
<td class="ht">Send reminders?
<span class="tooltip">this is the tooltip alshdgwh gahfguo
wfhg fghwoug wugw hgrwuog hwaur guoarwhg rwu</span>
</td>
</table>

Applying an ellipsis to multiline text

I finally found a solution to do what I want.
As p a paragraphe and article the wrapper.
If you want to apply ellipsis to p depending on article height (which also depends on window height), you need to get the height of the article, the line-height of the p and then articleHeight/lineHeight to find the number of line-clamp that can be added dynamically then.

The only thing is the line-height should be declared in the css file.

Check the following code. If you change the height of the window, the line-clamp will change. Can be great to create a plug-in aiming to do that.

jsfiddle

function lineclamp() {  var lineheight = parseFloat($('p').css('line-height'));  var articleheight = $('article').height();   var calc = parseInt(articleheight/lineheight);  $("p").css({"-webkit-line-clamp": "" + calc + ""});}

$(document).ready(function() { lineclamp();});
$( window ).resize(function() { lineclamp();});
article {  height:60%;  background:red;  position:absolute;}
p { margin:0; line-height:120%; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><article> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque lorem ligula, lacinia a justo sed, porttitor vulputate risus. In non feugiat risus. Sed vitae urna nisl. Duis suscipit volutpat sollicitudin. Donec ac massa elementum massa condimentum mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla sollicitudin sapien at enim sodales dapibus. Pellentesque sed nisl eu sem aliquam tempus nec ut leo. Quisque rutrum nulla nec aliquam placerat. Fusce a massa ut sem egestas imperdiet. Sed sollicitudin id dolor egestas malesuada. Quisque placerat lobortis ante, id ultrices ipsum hendrerit nec. Quisque quis ultrices erat.Nulla gravida ipsum nec sapien pellentesque pharetra. Suspendisse egestas aliquam nunc vel egestas. Nullam scelerisque purus interdum lectus consectetur mattis. Aliquam nunc erat, accumsan ut posuere eu, vehicula consequat ipsum. Fusce vel ex quis sem tristique imperdiet vel in mi. Cras leo orci, fermentum vitae volutpat vitae, convallis semper libero. Phasellus a volutpat diam. Ut pulvinar purus felis, eu vehicula enim aliquet vitae. Suspendisse quis lorem facilisis ante interdum euismod et vitae risus. Vestibulum varius nulla et enim malesuada fringilla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque lorem ligula, lacinia a justo sed, porttitor vulputate risus. In non feugiat risus. Sed vitae urna nisl. Duis suscipit volutpat sollicitudin. Donec ac massa elementum massa condimentum mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla sollicitudin sapien at enim sodales dapibus. Pellentesque sed nisl eu sem aliquam tempus nec ut leo. Quisque rutrum nulla nec aliquam placerat. Fusce a massa ut sem egestas imperdiet. Sed sollicitudin id dolor egestas malesuada. Quisque placerat lobortis ante, id ultrices ipsum hendrerit nec.</p></article>

Tooltip : Center a tool tip in table

table tbody td {width:100px;max-width:130px;white-space: nowrap;  text-overflow: ellipsis;  overflow-x: hidden;}            [data-tooltip] {              position: relative;              z-index: 1000000 !important;              cursor: pointer;              margin: 0 auto;            }
/* Hide the tooltip content by default */ [data-tooltip]:before, [data-tooltip]:after { visibility: visible; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=0)"; opacity: 1; pointer-events: none; transition: all 0.5s ease-out; }
/* Position tooltip above the element */ [data-tooltip]:before { position: absolute; top: -60%; padding: 5px 10px; width: auto; left: 50%; transform: translateX(-50%); margin: 0 auto; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; background-color: #000; background-color: hsla(0, 0%, 20%, 0.9); color: #fff; content: attr(data-tooltip); text-align: center; font-size: 11px; line-height: 1.2; }
/* Triangle hack to make tooltip look like a speech bubble */ [data-tooltip]:after { position: absolute; top: 5%; left: 50%; transform: translateX(-50%); width: 0; border-top: 5px solid #000; border-top: 5px solid hsla(0, 0%, 20%, 0.9); border-right: 5px solid transparent; border-left: 5px solid transparent; content: " "; font-size: 0; line-height: 0; }
/* Show tooltip content on hover */ [data-tooltip]:hover:before, [data-tooltip]:hover:after { visibility: visible; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=100)"; opacity: 1; transition: all 0.5s ease-in; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"><div class="table-responsive"><table class="table"><thead><tr><th>Caption 1</th><th>Caption 2</th><th>Caption 3</th><th>Caption 4</th><th>Caption 5</th><th>Caption 6</th></tr></thead><tbody><tr><td >Some data Some data Some data Some data </td>
<td data-tooltip="Some data Some data Some data Some data">Some data Some data Some data Some data </td>
<td >Some data Some data Some data Some data </td>
<td >Some data Some data Some data Some data </td>
<td >Some data Some data Some data Some data </td>
<td >Some data Some data Some data Some data </td></tr></tbody></table></div>

Showing truncated text on hover using CSS ellipsis overlaps text below it

You can just add height:auto to the hover state and it'll work just fine:

JS Fiddle

.name{    width:120px;    color: #0079c1;    height: 2em;     line-height: 1em;     font-size: 20px;    font-weight: 400;    text-overflow: ellipsis;    margin-bottom: 12px;    cursor: pointer;    word-break: break-all;    overflow:hidden;    white-space: nowrap;}.name:hover{    overflow: visible;     white-space: normal;    height:auto;  /* just added this line */}
<p class="name">Lorem ipsum lorem ipsum lorem ipsum ipsum lorem ipsum</p><span>  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quidem voluptate deserunt consequatur velit, alias ullam fuga aspernatur, ut doloremque eos fugiat quo a accusamus minus distinctio quasi, recusandae excepturi molestiae.</span>

Insert ellipsis (...) into HTML tag if content too wide

I've got a solution working in FF3, Safari and IE6+ with single and multiline text

.ellipsis {
white-space: nowrap;
overflow: hidden;
}

.ellipsis.multiline {
white-space: normal;
}

<div class="ellipsis" style="width: 100px; border: 1px solid black;">Lorem ipsum dolor sit amet, consectetur adipisicing elit</div>
<div class="ellipsis multiline" style="width: 100px; height: 40px; border: 1px solid black; margin-bottom: 100px">Lorem ipsum dolor sit amet, consectetur adipisicing elit</div>

<script type="text/javascript" src="/js/jquery.ellipsis.js"></script>
<script type="text/javascript">
$(".ellipsis").ellipsis();
</script>

jquery.ellipsis.js

(function($) {
$.fn.ellipsis = function()
{
return this.each(function()
{
var el = $(this);

if(el.css("overflow") == "hidden")
{
var text = el.html();
var multiline = el.hasClass('multiline');
var t = $(this.cloneNode(true))
.hide()
.css('position', 'absolute')
.css('overflow', 'visible')
.width(multiline ? el.width() : 'auto')
.height(multiline ? 'auto' : el.height())
;

el.after(t);

function height() { return t.height() > el.height(); };
function width() { return t.width() > el.width(); };

var func = multiline ? height : width;

while (text.length > 0 && func())
{
text = text.substr(0, text.length - 1);
t.html(text + "...");
}

el.html(t.html());
t.remove();
}
});
};
})(jQuery);

Changing :hover to touch/click for mobile devices

If you use :active selector in combination with :hover you can achieve this according to w3schools as long as the :active selector is called after the :hover selector.

 .info-slide:hover, .info-slide:active{
height:300px;
}

You'd have to test the FIDDLE in a mobile environment. I can't at the moment.

correction - I just tested in a mobile, it works fine



Related Topics



Leave a reply



Submit