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)
This article introduces the sample code of CSS3 t...
Today I have a question about configuring MySQL d...
1. Changes in MySQL's default storage engine ...
Managing disk space is an important daily task fo...
Table of contents 2. Stack analysis using pt-pmap...
In the course of work, you will encounter many ca...
Nginx log description Through access logs, you ca...
Today I encountered a very strange situation. Aft...
Async Hooks is a new feature of Node8. It provide...
Today at work, a friend I added temporarily asked ...
Preface This article mainly introduces the releva...
Table of contents 1. beforeunload event 2. Unload...
MySQL installation tutorial, for your reference, ...
I searched the entire web and found all kinds of ...
Table of contents Million-level data processing s...