HTML Element Style How to - Auto-sizing images in a HTML CSS block as browser window resizes








Question

We would like to know how to auto-sizing images in a HTML CSS block as browser window resizes.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
img {<!--from w w w . j  ava2s . co  m-->
  width: 50%;
  height: auto;
}
</style>
</head>
<body>
  <ul>
    <li><img src="http://www.java2s.com/style/download.png" /></li>
  </ul>
</body>
</html>

The code above is rendered as follows: