CSS - calc() on font-size - changing font size based on container size

前端 未结 4 1650
别跟我提以往
别跟我提以往 2021-01-17 15:34

I have a situation where I have a container element (div) that contains text. This text will sometimes be really large - not paragraph large, but it can potenti

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 15:45

    Here a possible solution:

    http://codepen.io/CrocoDillon/pen/fBJxu

    p {
      margin: 0;
      font-size: calc(4vw + 4vh + 2vmin);
      /* See:
       * http://codepen.io/CrocoDillon/pen/jgmwt
       * For some math behind this
       */
    }
    

    Font-size is calculated with available size using a function that is not perfect, but may be adjusted to work well in some cases.

提交回复
热议问题