HTML / CSS - adjust font-size to fill parent height and width

前端 未结 5 1037
梦毁少年i
梦毁少年i 2020-12-03 11:04

I have a

element that resizes as the browser window resizes.

Inside the

I have a paragraph of text:



        
5条回答
  •  自闭症患者
    2020-12-03 11:44

    HTML

    Paragraph of text. Paragraph of text. Paragraph of text.

    CSS

    #change { 
        width: 80%; 
        height: 80%; 
        border: 1px solid black; 
        overflow: hidden; 
        font-size: 1em; 
    } 
    

    JAVASCRIPT

    $(function() { 
        while( $('#change div').height() > $('#change').height() ) { 
            $('#change div').css('font-size', (parseInt($('#change div').css('font-size')) - 1) + "px" ); 
        } 
    }); 
    

提交回复
热议问题