CSS Layout How to - Change font size depending on resolution








Question

We would like to know how to change font size depending on resolution.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
html {<!--from   w ww.  j a  v a  2 s . c  o m-->
  font-size: 62.5%;
}

body {
  font-size: 1em;
}

@media ( max-width : 300px) {
  html {
    font-size: 70%;
  }
}

@media ( min-width : 500px) {
  html {
    font-size: 80%;
  }
}

@media ( min-width : 700px) {
  html {
    font-size: 120%;
  }
}

@media ( min-width : 1200px) {
  html {
    font-size: 200%;
  }
}
</style>
</head>
<body>resize window</body>
</html>

The code above is rendered as follows: