Display a Resized and Cropped Image using CSS
It helps to resize and crop any image dynamically for pre-defined position on a web page. The resized and cropped image is used in the web pages. There is a way where we can move the cropped image around within the div.
- Regular width and height that squeeze the image to fit in that pre-defined position.
Example:<!DOCTYPE html><html><head><!-- Style to set the height and widthof image --><style>img {width:200px;height:120px;border:2px solid green;}</style></head><bodystyle="text-align:center"><imgsrc=</body></html>chevron_rightfilter_noneOutput:

- Regular width, height and background position using the image as a background image that fit in that pre-defined position (randomly cropped).
Example:<!DOCTYPE html><html><head><style>div {background-image:url(width:200px;height:120px;background-position:center;border:2px solid green;}</style></head><body><center><div></div></center></body></html>chevron_rightfilter_noneOutput:

- It is the final procedure to cropped the image and also it can be resized. In this method we can move the image within the div. Use negative margin to move the image around within the div.
Example:
<!DOCTYPE html><html><head><style>.crop {width: 200px;height: 120px;overflow: hidden;border:2px solid green;}.crop img {width: 450px;height: 300px;margin: -30px 0 0 -280px;}</style></head><body><center><divclass="crop"><imgsrc=alt="cropped image"></div></center></body></html>chevron_rightfilter_noneOutput:
- What is the difference between display: inline and display: inline-block in CSS?
- Convert an image into grayscale image using HTML/CSS
- How do I get PHP errors to display?
- CSS | Display property
- Display div element on hovering over <a> tag using CSS
- How Facebook Display Ads for something you searched
- HTML | DOM Style display Property
- Display Property in Bootstrap with Examples
- Neon Text Display Using HTML & CSS
- How to display HTML tags as plain text using PHP
- How to display bootstrap carousel with three post in each slide?
- How do you display JavaScript datetime in 12 hour AM/PM format?
- Display the number of links present in a document using JavaScript
- Hide or show elements in HTML using display property
- How to display multiple horizontal images in Bootstrap card ?
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



