I am facing a challenge in selecting the last element of the first row and the first element of the last row within a flex container.
The setup involves a flex-wrap: wrap;
for my flex container where all elements have flex: auto;
with different sizes. This arrangement allows the elements to justify themselves within the container, while also having rounded corners on the corner elements.
However, the issue arises when I dynamically hide/show elements using events like click. Each time the layout changes, I need to ensure that the corner elements retain their rounded appearance. In a grid container, I would use nth-child
, but in a flex container where the number of elements per row varies, I require a more flexible solution.
I have come up with a jQuery solution (link provided below), but it feels bulky and cumbersome. I believe there must be a smarter or simpler selector that I am missing out on.
I would greatly appreciate any assistance in optimizing the code so that myself and others can benefit from it.
edit: Just made some improvements to the code http://jsfiddle.net/aj1vk0rv/1/