Is it possible to adapt font size to div width with CSS?

前端 未结 5 1591
刺人心
刺人心 2020-12-15 17:47

I have a div with 70% width, and here’s what I want to do:

  • Put some words in that div
  • Adapt font size so that those words occupy all div
5条回答
  •  隐瞒了意图╮
    2020-12-15 18:05

    Yes but I think you need to use JS(jQuery).

    JS:

    $(function(){
    
    var box = $('.box');
    var boxWith = box.width();
    
    $('.box h1').css('font-size',boxWith);
    
    });
    

    https://jsfiddle.net/moongod101/sdfaatp8/

提交回复
热议问题