Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling text using CSS

Tags:

css

What is and is there a way scale text using CSS based on the amount of text within a DIV.

I've this page I've created at http://www.directiongroup.com/tweethearts/ and the CSS for the text is (with a fixed size of 32px):

.jta-tweet-text

{
    color: #ed1c24;
    font-size: 32px;
    text-transform: uppercase;
    line-height: 30px;
    font-weight: normal;
    font-family: 'BebasNeueRegular', Arial, Helvetica, sans-serif;
    text-shadow: 0px 1px 0px #FFFFFF;
}

Many Thanks

like image 723
Tim Avatar asked Feb 10 '12 10:02

Tim


2 Answers

You can't do this with CSS alone but you could do it with a bit of JavaScript.

Counting the number of characters in the text and setting the CSS font-size property as required.

Here's a quick example using jQuery: http://jsfiddle.net/pjByL/

$('.heart').each(function(){
var textLength = $(this).text().length
    if(textLength > 26)
    {
       $(this).css('font-size', '10px');
    }
});
like image 116
Jamie Dixon Avatar answered Nov 11 '22 21:11

Jamie Dixon


You can't achieve that with css you have to use java script for this check this may that's help you

http://fittextjs.com/

like image 35
sandeep Avatar answered Nov 11 '22 21:11

sandeep