Home >Web Front-end >CSS Tutorial >How Can CSS Ensure Uniform Image Sizing for Images of Varying Dimensions?
Achieving Uniform Image Sizing for Varying Images with CSS
Creating an appealing image gallery often requires images of consistent size, regardless of their original dimensions. This can pose a challenge when working with images of differing heights and widths. However, CSS offers a solution to make all images appear uniform.
Solution:
To set the dimensions of all images to 100px by 100px, utilize the following CSS code:
img { float: left; width: 100px; height: 100px; object-fit: cover; }
Implementation:
Example:
To illustrate this concept, consider the following HTML and CSS code:
<img src="image1.jpg"> <img src="image2.jpg"> <img src="image3.jpg">
img { float: left; width: 100px; height: 100px; object-fit: cover; }
This code will render the images as square thumbnails with a consistent height and width of 100px. The images will be resized and cropped to fit within these dimensions while maintaining their original proportions.
The above is the detailed content of How Can CSS Ensure Uniform Image Sizing for Images of Varying Dimensions?. For more information, please follow other related articles on the PHP Chinese website!