Reputation: 3117
I have HTML like :
<div class="box">
<a href="#">Stackoverflow is very useful site and I love it</a>
</div>
and CSS like :
.box {
width:230px;
height:50px;
line-height:50px;
background:#eee;
}
.box a {
color:#000;
}
I want create shorten text of link. If it itself overflow the box
class, then take it by "...". How can I do that with css or jquery?
Check jsfiddle here
Upvotes: 1
Views: 230
Reputation: 528
Try this:
$(document).ready(function() {
var showChar = 37;
var ellipsestext = "...";
$('.box').each(function() {
var content = $(this).find("a").html();
if(content.length > showChar) {
var a = content.substr(0, showChar);
var b = content.substr(showChar-1, content.length - showChar);
var html = a + ' ' + ellipsestext;
$(this).find("a").html(html);
}
});
});
Upvotes: 1
Reputation: 782
try this,
.box{
width:230px;
height:50px;
line-height:50px
;background:#eee;
overflow:hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.box a{color:#000}
Upvotes: 1
Reputation: 3395
Try this:-
.box{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Upvotes: 2
Reputation: 16140
Add following styles to .box
:
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
Working sample: http://jsfiddle.net/qLzK7/
Upvotes: 6
Reputation: 85545
You need to set text-overflow: ellipsis for that purpose see this link for more info
Upvotes: 3