Vanyatwo Vanyatwo - 2 months ago 10
CSS Question

Selector for an element alone in a row?

We have flex container with 2 child elements.

When we resize window, and one of flex item wraps, we have each element on its own row.

Is it any selector like

:when-alone-in-row
?

.flex-parent {flex-flow: row wrap}
.flex-child
.flex-child

Answer

No, there is no selector similar to :when-alone-in-row.

However, when you want to select the first and last elements from a group of siblings (which would be the case here since you're dealing with only two flex items), you can use the :first-child and :last-child pseudo classes.

Of course, the styles applied by these selectors will work even when both items are on the same line, unless they're applied in a media query.