HTML Element Style How to - Crop effect on image








Question

We would like to know how to crop effect on image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.imgDiv {<!--from  w  w w .  j a v a 2 s.com-->
  width: 64px;
  height: 64px;
  overflow: hidden;
}

.imgDiv>img {
  position: relative;
  left: -32px;
  top: -32px;
}
</style>
</head>
<body>
  <div class="imgDiv">
    <img
      src="http://www.java2s.com/style/download.png"
      width="128" height="128" />
  </div>
</body>
</html>

The code above is rendered as follows: