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

前端 未结 4 1693
别跟我提以往
别跟我提以往 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:55

    Just a clarification:

    if you use something like:

    font-size: -webkit-calc(100% + 30px);
    font-size:        -calc(100% + 30px);
    

    what this does is add 30px to the 100% default font size, it can't be linked to the container width.

    Although, you can do math there like:

    font-size: -webkit-calc( 100% * 0.09479166667 - 6.666666669px );
    font-size:        -calc( 100% * 0.09479166667 - 6.666666669px );
    

    ... but it will just calculate it against the 1em.

提交回复
热议问题