Why Percentage Padding Breaks Flex Items
Consider a scenario where a
To understand this behavior, we delve into the calculation involved with percentage paddings. Percentage padding values are relative to the width of the containing block. However, the width of the containing block is determined by its content.
In this case, the width of the
console.log(document.querySelector('ul').offsetWidth);
The complexity lies in the fact that we cannot determine the percentage padding values before calculating the width. Hence, we first calculate the width based on the content.
Therefore, when percentage paddings are used, the browser struggles to determine the width of the containing block, resulting in the multi-line behavior. In contrast, with fixed paddings, the width is explicitly defined, eliminating this issue.
The above is the detailed content of Why Do Percentage Paddings on Flex Item Children Break the Parent Flex Container?. For more information, please follow other related articles on the PHP Chinese website!