Crop Image by CSS

Posted By : Balraj Singh | 30-Jun-2015

Let we have an element of fixed Height and width. We placed an large size's image in it. Then we can crop the image by css and centre the image vertically and horizontally both in element.

I’m giving an example:-

let we have an element. which’s width is 100px and height 100px and now we take an large image in the element.

HTML

<div>
	<img src=“dummy-large-image” class=“dummy-image">
 </div>
 

 

CSS

.dummy-image {
	text-align: center;
	transform:translateY(-50%);
	-webkit-transform:translateY(-50%);
	-moz-transform:translateY(-50%);
}
 

THANKS

 

About Author

Author Image
Balraj Singh

Balraj is a creative UI designer with experience and capabilities to build compelling UI designs for Web and Mobile Applications. Balraj likes playing tech Quiz and loves bike riding.

Request for Proposal

Name is required

Comment is required

Sending message..