CSS Layout How to - Change H1 font size and color according to screen size








Question

We would like to know how to change H1 font size and color according to screen size.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.left {<!--   ww  w  . j a  v  a2 s . c o  m-->
  width: 32%;
  float: left;
  margin: 5px;
}

@media screen and (max-width: 1024px) {
  h1 {
    font-size: 10px;
    color: blue;
  }
}
</style>
</head>
<body>
  <div class="left">
    <h1>Title</h1>
    <p>Content</p>
  </div>
  ...
  <div class="left">
    <h1>Title Too Long Long</h1>
    <p>Content</p>
  </div>
</body>
</html>

The code above is rendered as follows: