Home >Web Front-end >CSS Tutorial >Why Do Flex Items Wrap When Using Percentage Padding?
Consider a scenario where a
When percentage padding is used, it is relative to the width of the containing block, in this case, the
Without fixed padding, the browser calculates the
To better illustrate this behavior, consider the following code:
li { display: inline-block; padding: 0 5%; /* Percentage padding */ border: 1px solid black; } header { display: flex; } ul { border:1px solid red; }
If we execute the following JavaScript in the console, we can see the width of the
console.log(document.querySelector('ul').offsetWidth);
This will output the width of the
The above is the detailed content of Why Do Flex Items Wrap When Using Percentage Padding?. For more information, please follow other related articles on the PHP Chinese website!