The meaning and benefits of flex: 1

后端 未结 3 927
清酒与你
清酒与你 2020-12-07 05:14

I stumbled upon flex: 1 today in some code and googled it to get some information about what it does. w3schools succinctly states:

Let al

3条回答
  •  暖寄归人
    2020-12-07 05:31

    At this detailed guide on the right hand side there is a statement in bold:

    "It is recommended that you use this shorthand property rather than set the individual properties. The short hand sets the other values intelligently."

    This I have found really is intelligent, meaning based on flex-direction and flex-wrap usually gives the desired result. I only, strictly only manipulate the properties separately by hand if I cannot get it with flex:1 - even if it requires DOM modification. In my opinion it makes your flex-use and the whole CSS more readable and understandable which is inevitable when writing high quality and maintainable code.

    To more specifically answer your question (as raised by @TylerH): every single case when you use flex to positioning/sizing then try flex:1 first. In most cases you will find the result satisfying and will leave you with maintainable code. If you need more specific/special positioning only then should you dig deeper into the parameters of flex.

提交回复
热议问题