chris hughes
chris hughes

Reputation: 45

How can I change the size of my text on a mobile device?

I know how to use the (font-size) attribute, but I only want the letters on a mobile device to get smaller when the letters reach a certain amount.....

When letters reach 40 characters, I want the letters to shrink so that it can fit in a mobile browser

Can this be done?

Upvotes: 0

Views: 58

Answers (1)

Preben
Preben

Reputation: 1287

You can use jquery to count the number of caracters inside a certain tag. For instance in a <p>like this:

http://jsfiddle.net/dL1zzdtg/1/

var XX = 40;

$('p').filter(function() {
    return $(this).text().length > XX;
}).addClass('long_paragraph');

You adjust the number of caracters in the XX = 40 above.

and in the css add:

p.long_paragraph {font-size:70%;}

enter image description here

(I found the javascript here )

Upvotes: 1

Related Questions