Bigger fonts on smaller screens without @media queries or javascript?

后端 未结 5 963
梦如初夏
梦如初夏 2020-12-29 09:29

Is there an alternative for @media queries to accomplish font-size inversely proportional to the screen size? (e.g.: opposite effect of 2vw, where the font gets

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 10:23

    You can't divide a px value by a viewport-width increment, but you can achieve this inverse size behavior reducing a px value by a viewport-width increment.

    Example:
    font-size: calc(40px - 2vw);

    Codepen DEMO

    Alternatively, you could use the other 3 units related to the viewport's size: vh vmin and vmax.

    Examples:
    font-size: calc(40px - 2vh);
    font-size: calc(200px - 20vmin);
    font-size: calc(200px - 20vmax);

    vw - Relative to 1% of the width of the viewport*;
    vh - Relative to 1% of the height of the viewport*;
    vmin - Relative to 1% of viewport's* smaller dimension;
    vmax - Relative to 1% of viewport's* larger dimension;

    *viewport = the browser window size.

    Source: w3schools

提交回复
热议问题