CSS Layout How to - Change img path based on screen resolution








Question

We would like to know how to change img path based on screen resolution.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
@media ( max-width : 900px) {
  img {<!--   ww w . ja v a2s.c o  m-->
    background: http://www.java2s.com/style/download.png;
    width: 0;
    height: 0;
    padding: 100px;
  }
}
</style>

</head>
<body>
  <img src="http://placehold.it/200x200" />
</body>
</html>

The code above is rendered as follows: