I have a flexbox element that can have any number of children. These children can have a different width (but not more than 100%), and are all the same height, so they form tidy rows. Illustration:
[.....] [....]
[.............]
[..] [....] [.]
[......]
I want to style the elements differently when there are more than three rows, than when there are only three, two or one row. Is there any way to do this with CSS?
I do not know how many child elements will be in one row. It could be one child per row, or two, or three. As in the illustration above. The elements are generated based on data that can change, so I can't fix them to x elements per row.
.parent {
display: flex;
flex-wrap: wrap;
}
.parent .child {
max-width: 100%;
background: red;
}
// can I do this?
.parent:has-more-than-three-lines .child {
background: blue;
}
I know I can use JavaScript to read the element's height and the children's height after it renders, and calculate how many rows there are. But I'd like to avoid that. If I have to give the child elements a fixed height, that's OK for me.
To be clear, I want to style all the children based on the parent's height, not just the ones in the additional rows.