MariaJackson1
12/19/2017 - 5:16 AM

Mike Riethmuller Article

Mike Riethmuller Article

https://madebymike.com.au/writing/fluid-type-calc-examples/


html {
  font-size: 16px;
}
@media screen and (min-width: 320px) {
  html {
    font-size: calc(16px + 6) * (100vw - 320px) / 680));
  }
}
@media screen and (min-width: 1000px) {
  html {
    font-size: 22px;
  }
}


That would scale font-size from a minimum of 16px (at a 320px viewport) to a maximum of 22px (at a 1000px viewport).

The math (credit Mike Riethmuller):

body {
  font-size: calc([minimum size] + ([maximum size] - [minimum size]) * ((100vw - [minimum viewport width]) / ([maximum viewport width] - [minimum viewport width])));
  
 For example, if we want the our font size in a range where 14px is the minimum size at the smallest viewport width of 300px and where 26px is the maximum size at the largest viewport width of 1600px, then our equation looks like this:
 body {
  font-size: calc(14px + (26 - 14) * ((100vw - 300px) / (1600 - 300)));