Responsive font size using CSS/jQuery

前端 未结 3 636
天涯浪人
天涯浪人 2021-01-17 01:57

I want to create a responsive text inside a div.

I tried jquery-textfill and FlowType, but they are not working for me at all.

FlowType does

3条回答
  •  青春惊慌失措
    2021-01-17 02:29

    CSS

    .internal{width:100%;height:100%}
    .external{width:auto;height:auto;background-color:yellow}
    

    JQuery

    $(".external").fitText(0.5);
    

    DEMO 1

    Update 1:

    CSS

    .internal{width:auto;height:auto;position:absolute;}
    .external{width:400px;height:50px;background-color:yellow;position:relative;}
    

    JQuery

    $(".external").fitText();
    

    DEMO 2

    Update 2:

    JQuery

    var ex=$(".external");
    var h=ex.height();
    var w=ex.width();
    ex.fitText(Math.min(h,w)/Math.max(h,w) );
    

    DEMO 3

    Update 4:

    Bigtext is a jQuery text plugin that automatically enlarge the font size of your text to fill its parent container, without overflowing the container Div. jQuery Bigtext Plugin

提交回复
热议问题