When you use justify-content: space-between
, the
flex container will arrange the
flex items so that they have equal spacing in between them. It's important to remember that this property should be applied to the parent container.
<div style={flexContainer}>
{fields.map(({ inLine }) => (
...
))}
</div>
If you need your content to wrap, you can utilize the flex-wrap
property. Setting flex-wrap: wrap
instructs the flex parent to wrap its children when they cannot fit in a single line. In this scenario, flex-basis
behaves like width and takes precedence over it. By setting the flex-basis
of an element to 100%
, you are essentially telling the flex parent that this item should take up the entire row, while giving other inLine elements a 0%
basis allows flex-grow
to determine their size relative to each other. If you require spacing between inline fields, you can use properties like margin
on those elements.
const flexContainer = {
display: "flex",
flexWrap: "wrap",
justifyContent: "space-between"
};
const style = inLine => ({
display: inLine ? "inline-flex" : "flex",
flexBasis: inLine ? "0" : "100%",
flexGrow: inLine ? "1" : "0",
});
For more information, check out the example on CodeSandBox: https://codesandbox.io/s/determined-sammet-xp2on?file=/src/Form.js