The clip property
The clip
property allows cropping an absolutely positioned element, leaving only the specified rectangular area visible.
The value is specified using the rect
function.
Syntax
selector {
clip: rect(top, right, bottom, left) | auto;
}
Preparing images
Let's take a nature image that we'll be cropping:
<img src="image.jpg" width="500">
:
Example
Let's crop the image, leaving only the central part visible:
<div class="container">
<img class="image" src="image.jpg">
</div>
.container {
position: relative;
width: 400px;
height: 300px;
}
.image {
position: absolute;
clip: rect(50px, 350px, 250px, 50px);
width: 400px;
height: 300px;
}
: