Why is padding expanding a flex item?

后端 未结 2 2066
感情败类
感情败类 2020-12-06 15:50

In the snippet below, the first row has two divs with flex-grow: 1. As expected, each div takes up 50% of the screen.

When adding padding to the left di

2条回答
  •  日久生厌
    2020-12-06 16:34

    That's the correct behaviour as far as I am aware.

    flex:1 is, of course, shorthand for:

    flex-grow:1;
    flex-shrink:1;
    flex-basis:0
    

    This allows the div to grow if necessary which, in this case, it does. It's not automatically going to maintain the flex-items as all the same size if they are, in fact, different.

提交回复
热议问题