Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the text shrink automatically to fit in the div?

Tags:

html

css

I know i can adjust the font size, but I want it to shrink to fit the div automatically when it is viewed on a different platform which reads font sizes differently for example.

See the fiddle: http://jsfiddle.net/08pyzgx4/

<body>
    <div style="width:600px; height:58px; max-width: 600px; background-image:url(http://itrace.co.za/images/emailfiles/banner.png);     background-repeat:no-repeat; display:block; max-width: 600px; font-family:Arial, Helvetica, sans-serif; font-size:19px; color:#000;     text-align:center; padding-top:12px;"><b>Bla Bla Bla Bla Bla Bla </b>

        <div style="height:16px; max-height:16px; padding-left:88px; padding-right:88px; margin-top:18px; font-size:0.6em; letter-spacing:-0.02em; position:relative;"><strong>Website: </strong>www.blabla.co.za | <strong>E-mail: </strong>[email protected] | <strong>Control Centre: </strong>08600-22-blabla</div>
    </div>
</body>
like image 556
Chips147 Avatar asked Feb 19 '15 10:02

Chips147


1 Answers

You can do it like this....and don't forget to add js library.

this is the fiddle...http://jsfiddle.net/f6sx474j/ Try by increasing the text i checked it and its working properly.

<div style="width:600px; 
height:58px;
max-width: 600px;
background-image:url(http://itrace.co.za/images/emailfiles/banner.png); 
background-repeat:no-repeat;
display:block; max-width: 600px;
font-family:Arial, Helvetica, sans-serif; 
font-size:19px; color:#000;     
text-align:center; padding-top:12px;">
<b>Bla Bla Bla Bla Bla Bla </b>
<div id="abc" style="height:16px;
 display: inline-block; 
 max-height:16px; 
 padding-left:88px;
 padding-right:88px; 
 margin-top:18px; 
 font-size:0.6em; 
 letter-spacing:-0.02em;
  position:relative;">
<strong>Website: </strong>www.blabla.co.za |
 <strong>E-mail:   </strong>
 [email protected] [email protected] info@b
 <strong>Control Centre: </strong>
 08600-22-blabla</div>
</div>

//And this is your js

<script type="text/javascript">
$(function() {
var div = $('#abc');
var fontSize = parseInt(div.css('font-size'));
do {
    fontSize--;
    div.css('font-size', fontSize.toString() + 'px');
    } while (div.width() >= 400);
   });
 </script>
like image 193
Abdul Muheet Avatar answered Oct 10 '22 03:10

Abdul Muheet