The insignificant 1. Flex family There are many properties in flex, and the ones we often use are as follows: .container { display: flex; } .container > .left { flex: 1; } .container > .right { flex: 1; } This makes it easy to achieve a layout that is equally divided on the left and right. Let's look at an example that causes the problem: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> <style> div { padding: 5px; border: 1px solid #ccc; } .no-effect { align-items: center; margin: 100px; width: 200px; color: #999; } .no-effect > div:first-of-type { margin-right: 10px; } p { color: red; } .no-wrap { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } </style> </head> <body> <div style="display: flex;" class="no-effect"> <div style="flex: 0 0 80px">I am shorter</div> <div style="flex: auto"> <p class="no-wrap">I am very long, no kidding, I can grow to no end</p> </div> </div> </body> </html> The effect we want: But the actual effect: Why does this happen? 2. Flex-basis gets in the way flex-grow: 1; flex-shrink: 1; flex-basis: auto; Our left div does not expand or shrink, and its width is fixed at 80px; the right div automatically fills the remaining width, which is 200px - 80px = 120px, but the actual effect is far beyond 120px. This is due to the calculation when flex-basis is auto. Let's look at the history of flex-basis: auto:
So when we don't set In this way, when the internal The default value of Common elements: 3. Solution Once we know the cause, we can then prescribe the right remedy.
Now that we have introduced three solutions, let’s talk about why the first two can be solved. The first one is very simple. The width is set to 0, but So what about the second one? The second case is more complicated. When we set min(max(preferred minimum width, available width), preferred width) Translated into adult language:
shrink-to-fit width = min(max(minimum width, available width), preferred width) So let's calculate:
By calculation, we can get: max(0, 272) = 272 min(272, 98) = 98 So the final width is the remaining 98px. When we manually set Summarize CSS is not as easy to use as we think, there are rules to follow, but the process of finding it is a bit complicated... If you encounter something you don't understand, you can read more about how it came about and what it does, and you will understand the idea of solving it. |
<<: Configure nginx to redirect to the system maintenance page
>>: JavaScript basics of this pointing
Scenario 1: To achieve a semi-transparent border:...
1. One-click installation of Mysql script [root@u...
This article shares the MySQL installation tutori...
async function and await keyword in JS function h...
We all know that we can use the mkdir command to ...
Table of contents Preface🌟 1. API Introduction 2....
1. Download 1. MySQL official website download ad...
Table of contents process Demo Mini Program Backe...
Let's take a look at the detailed method of b...
I started working on my final project today, but ...
Download the latest version of MySQL for Ubuntu L...
{ {}} Get the value, the original content of the ...
Table of contents 1. typeof 2. instanceof 3. Diff...
The previous article introduced a detailed exampl...
The legend component is a commonly used component...