Question:
In the context of flexbox, is it possible to align two items left and one item right? For a visual representation, refer to the provided JSFiddle link.
Answer:
To achieve right alignment for one flex child, set its margin-left: auto;.
According to the flex specification:
Auto margins on the main axis can be used to separate flex items into different "groups." This allows for the creation of UI patterns such as action bars with some items aligned left and others right.
Therefore, the following CSS will align the last div element in the provided example to the right:
.wrap div:last-child { margin-left: auto; }
By combining this technique with your existing flexbox styles, you can achieve the desired layout without requiring multiple blocks of code.
The above is the detailed content of How Can I Right-Align One Flexbox Item While Others Remain Left-Aligned?. For more information, please follow other related articles on the PHP Chinese website!