Understanding the Issue
In your situation, you have multiple buttons arranged in a row using flexbox. You want these buttons to increase their width proportionally to fill the remaining row space while maintaining their original width differences. However, setting flex: 1 on each button is resulting in all buttons becoming equal in width.
Solution: Switch to Flex: Auto
The key to achieving your desired outcome lies in choosing the correct value for flex-grow. Instead of flex: 1, you should use flex: auto.
How Flex-Grow Works
flex-grow distributes free space in the container among flex items based on two factors:
When using flex: 1, you are setting flex-basis to 0 and flex-grow to 1. This means that flexbox treats all space in the row as free space, resulting in equal distribution among all items regardless of their content.
On the other hand, flex: auto sets flex-basis to auto, which considers the size of the item's content before distributing the free space. This ensures that items maintain their original size differences while still filling the remaining row space.
Example
In your code, replace flex: 1 with flex: auto for each button:
This will allow the buttons to expand based on their original widths, fulfilling your requirement.
The above is the detailed content of How Can I Make Flexbox Items Expand Proportionally Based on Their Initial Sizes?. For more information, please follow other related articles on the PHP Chinese website!