Philip
Philip

Reputation: 7166

css h1 font-size as big as width

Is it possible to tell a h1 to size the text so it fills the full 100% width of the element?

Like this.

enter image description here

code:

<h1>FOO</h1>
<h1>BAAR</h1>

Upvotes: 4

Views: 4339

Answers (3)

Dan Ovidiu Boncut
Dan Ovidiu Boncut

Reputation: 3165

One possible solution with jQuery would be:

var cs=$("#content").width();
$("h1").each(function(){
var hs=$(this).width();
while(hs<cs)
{
    $("h1").css("font-size",hs+0.01+"px");
    var hs=$(this).width();
}
while(hs>cs)
{
    $("h1").css("font-size",hs-0.01+"px");
    var hs=$(this).width();
}

})

Upvotes: -1

user1157393
user1157393

Reputation:

Try this plugin.

http://fittextjs.com/

It's great for responsive text.

EDIT:

jQuery("#element1").fitText(1.2, { minFontSize: '20px', maxFontSize: '540px' });
jQuery("#element2").fitText(1.2, { minFontSize: '40px', maxFontSize: '340px' });

Upvotes: 8

Philip
Philip

Reputation: 7166

I found a plugin called bigtext that works pretty well, will wait for comments though.

https://github.com/zachleat/BigText

Upvotes: 0

Related Questions