What do “flex” and “justify-content” achieve that “text-align” doesn't?

后端 未结 3 1174
别跟我提以往
别跟我提以往 2020-11-27 08:26

These two ways to move a button to the right of its parent seem completely equivalent to me. Is there a reason to choose one over the other? Are there circumstances in which

3条回答
  •  天涯浪人
    2020-11-27 08:45

    Yes, the reason is vertical centering. The align-items: center is the key here, which allows the buttons to be vertically centered in the modal footer. This is hard to do without flex-boxes - you would need to resort to "hacks" like using position:absolute, or adding some precalculated amounts of padding on both sides, etc. Flexes (and Grids) allow developers to define layouts more succinctly.

    To answer your question - they didn't opt for justify-content:flex-end instead of text-align:right - instead, they opted for flex instead of block as the display box model (for vertical centering), and the justify-content usage comes naturally from that decision.

提交回复
热议问题