Skip to content

[css-selectors][css-flexbox] Pseudo-classes for flex-wrapped and rows elements #5150

@smhmd

Description

@smhmd

referencing: https://www.w3.org/TR/selectors-4/

proposed pseudo-classes: :first-wrap, :last-wrap, :first-wrap-row, :last-wrap-row, :nth-wrap-row()

The idea is to have pseudo-classes to help style wrapped flex items.

Given this HTML:

<ul>
  <li>one</li>
  <li>two</li>
  <li>three</li>
  <li>four</li>
  <li>five</li>
  <li>six</li>
  <li>seven</li>
  <li>eight</li>
  <li>nine</li>
</ul>

and this CSS:

ul {
  display: flex;
  flex-wrap: wrap;
}

ul > * + * {
  border-left: 2px solid black;
}

li {
  width: 150px;
}

output:
image


The possibility to style first (or last) wrapped elements with a pseudo-class:

ul:first-wrap {
  border: none;
}  

output 1:
image
output 2 (window resize):
image


The possibility to style entire flex rows:

ul:first-wrap-row > * {
  border-bottom: 2px solid black;
}

output 1:
image

output 2 (window resize):
image


:last-wrap, :last-wrap-row, and :nth-wrap-row() are self-explanatory.

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