Reputation: 1009
I've got a div with fixed width and a quite long text. This long text is set to appear in
one line via white-space: no-wrap
. The problem is, that I can't figure out how to make the font size of this text fit into the div (without making breaks to the text). Could anyone help please?
Example layout:
<div style="width: 100px; max-width: 100px;">
<span style="white-space: nowrap">This is a too long text to normally fit in</span>
</div>
Upvotes: 1
Views: 16108
Reputation: 1167
I think that another guy has the exact same request as yours. Have a look at this topic where several jQuery/CSS solutions have been found.
Upvotes: 0
Reputation: 88
Try this:
<div style="width: 100px; max-width: 100px;overflow: hidden;text-overflow: ellipsis;">
<span style="white-space: nowrap">This is a too long text to normally fit in</span>
</div>
Upvotes: 2
Reputation: 110
Set font size <span style="font-size:17px;white-space:
nowrap;">This is a too long text to normally fit in</span>
Upvotes: 0
Reputation: 2105
If you are allowed to add some library in your project, this one would do the trick :
https://github.com/jquery-textfill/jquery-textfill
You would add in javascript :
$('.truncate').textfill({ widthOnly: 100px });
And you also need to keep the css attribute
.truncate{
white-space: nowrap;
}
Upvotes: 0