When multiple images are introduced into a page, the image sizes may be inconsistent. However, if we want to display them in a consistent size, directly setting the image size will cause the image to deform. This is the problem we encountered. Let's see the solution. <div> <img src="imported image address" alt=""> </div> Method 1: Center the img element vertically and set its height and width to a minimum full-screen value div{ position:relative; width: 100px; height: 100px; overflow:hidden; } div img{ position: absolute; top: 50%; left: 50%; display: block; min-width: 100%; min-height: 100%; transform:translate(-50%,-50%); } Method 2: Set the CSS style of img and add object-fit: cover, which is similar to the background-size: cover of the background image in CSS3; div{ width: 100px; height: 100px; } div img{ width: 100%; height: 100%; object-fit:cover; } This concludes this article on how to use CSS to fill the parent container div with img images and achieve adaptive container size. For more information about how to use CSS to fill container content with img images, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Implementation script for scheduled database backup in Linux
>>: SQL implementation of LeetCode (181. Employees earn more than managers)
As shown below: XML/HTML CodeCopy content to clip...
The attributes of the <TR> tag are used to ...
Are you still using rem flexible layout? Does it ...
1. Introduction This article does not have screen...
This article shares the specific code of js to im...
This article example shares the specific code of ...
When you write buttons (input, button), you will f...
Install MySQL for the first time on your machine....
Download Download address: https://dev.mysql.com/...
Everything needs a foundation. To build a house, ...
Background description: On an existing load balan...
Demand background The team has the need for integ...
Use Javascript to implement a message board examp...
Maybe you are using include files here, which is u...
After starting Docker, let's take a look at t...