I need fit text within the fixed width container, for example i have 150px width in particular div but text is dynamically will come so based one font size change and fit to the container, kindly suggest
Note: only javascript
I need fit text within the fixed width container, for example i have 150px width in particular div but text is dynamically will come so based one font size change and fit to the container, kindly suggest
Note: only javascript
You could use this method, stolen from this answer:
How to: Reduce font-size if a line breaks
Written by AlexK
var divWidth = $("#theDiv").width();
var text = $("#text");
var fontSize = 12;
while (text.width() > divWidth)
text.css("font-size", fontSize -= 0.5);
text.css("display", "inline");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="theDiv" style="width:200px; border:1px solid red;">
<span id="text" style="display:none;white-space:nowrap;">This sentence is too large to fit within the div.</span>
</div>
Note that you need JQuery for this.
If you don't want to use jQuery, it shouldn't be hard to replace it with JS.