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

前端 未结 5 1593
刺人心
刺人心 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:17

    Perhaps not quite what you're looking for, but something - You can make both the font and the element relative to view width.

    p {
      font-size: 5vw;
      background-color: red;
      width: 50vw;
    }

    I'm a P!

提交回复
热议问题