When writing a flex layout, is there a way to make two elements, one to the left and one to the center?

in the case of writing css, two elements are arranged horizontally, such as the arrow and title in the figure. I wonder if flex can center them one to the right and the other

.

the current method I use is that the parent element block and then the arrow is positioned relative to each other, the title is set wide, and margin 0 auto

I don"t know if you have any good ways to use

.

clipboard.png

May.01,2021

  1. use flex: to add a block on the right to form a structure arrow-title-width block as wide as the arrow , which solves the problem and is a little less elegant.
  2. use absolute positioning: place the arrow in the title block, and the arrow can be positioned absolutely relative to the title block (recommended)

you can add a third element and then hide it.


justify-content: space-between;

add one more empty element


can be achieved by giving the icon on the left a width, and then setting

on the right
flex: 1;
text-align: center;

so that the middle text is to the right, you can also add an element to the right, but hide it.


justify-content: space-between;
align-item:center;
add one more element,
-


simple and rude, add one more element, left, middle and right, the empty element on the right is the same width as the left,

Menu