Detailed explanation of the solution to image deformation under flex layout

Detailed explanation of the solution to image deformation under flex layout

Flex layout is a commonly used layout method nowadays, but sometimes it can cause some minor problems. When I was using flex layout to make an avatar on the left and text on the right, I found that when the width of the image was fixed, the width of the image still changed.

The picture below shows that the avatar should be round, but it has been squeezed and deformed.

<div class="people">
	<img class="avatar" src="./avatar.jpg" alt="avatar">
	<div class="des">
		<p>Tony</p>
		<p>That’s right, I am your teacher Tony, come and get your hair cut by me! </p>
	</div>
</div>
/* Parent element */
.people {
	display: flex;
}
/* avatar*/
.avatar {
	width: 64px;
	height: 64px;
	border-radius: 32px;
}
/* Character introduction*/
.des {
	margin-left: 24px;
}

A common way to search online is to wrap a div outside the img tag.

<div class="people">
	<div><img class="avatar" src="./avatar.jpg" alt="avatar"></div>
	<div class="des">
		<p>Tony</p>
		<p>That’s right, I am your teacher Tony, come and get your hair cut by me! </p>
	</div>
</div>

Another simpler way is to add flex-shrink: 0 directly to the avatar's css.

/* avatar*/
/* The flex-shrink property defines the shrink ratio of the item. The default value is 1, which means that if there is not enough space, the item will shrink. */
/* If the flex-shrink property of an element is 0 and the other items are 1, the one with a value of 0 will not shrink when there is insufficient space. */
.avatar {
	flex-shrink: 0;
	width: 64px;
	height: 64px;
	border-radius: 32px;
}

This concludes this article on the solution to image deformation under flex layout. For more relevant flex image deformation content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  Absolute path URL and relative path URL in html and subdirectory, parent directory, root directory

>>:  An article to understand what is MySQL Index Pushdown (ICP)

Recommend

Linux automatic login example explanation

There are many scripts on the Internet that use e...

How to implement JavaScript output of Fibonacci sequence

Table of contents topic analyze Basic solution Ba...

How to install a virtual machine with Windows services on Mac

1. Download the virtual machine Official download...

WeChat applet implements calculator function

WeChat Mini Programs are becoming more and more p...

Summary of several common methods of JavaScript arrays

Table of contents 1. Introduction 2. filter() 3. ...

Tips for using the docker inspect command

Description and Introduction Docker inspect is a ...

Summary of discussion on nginx cookie validity period

Every visit will generate Cookie in the browser, ...

CSS3 to achieve floating cloud animation

Operation effect html <head> <meta chars...

Deploy Varnish cache proxy server based on Centos7

1. Varnish Overview 1. Introduction to Varnish Va...

Specific use of Linux gcc command

01. Command Overview The gcc command uses the C/C...

MySQL Optimization Solution Reference

Problems that may arise from optimization Optimiz...

js to achieve sliding carousel effect

This article shares the specific code of js to ac...

Detailed explanation of the usage of MySQL data type DECIMAL

MySQL DECIMAL data type is used to store exact nu...

10 skills that make front-end developers worth millions

The skills that front-end developers need to mast...