Skip to content

[css-flexbox][css-align] Proposal: justify-items and justify-self to align flex items that are alone on their line #11244

@benface

Description

@benface

Ok, I have to say that this is a very rough/raw idea, but the problem it would solve is a real one: there's currently no way to have a flex container with justify-content: space-between and flex-wrap: wrap and control the horizontal alignment ("justification"?) of the items that end up alone on their line (they are always start-aligned, at least in LTR). A workaround exists to make them end-aligned, but I couldn't find any to make them center-aligned. What if it was as simple as this?

.flex {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  justify-items: center; /* <-- this currently doesn't work; `justify-items` is ignored in flex layout */
}

Or, a more concrete example where we only want to center-align a specific item when it wraps:

<footer style="display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem;">
  <nav>Nav content here</nav>
  <div>Social links here</div>
  <p style="justify-self: center; text-align: center;">
    Copyright © 2024 Example Company
  </p>
</footer>

Check out that example on Codepen. There is currently no way to center-align the copyright notice without using a media query, which is just sad.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions