Here's the deal:
- You've got markup you don't control
- It includes images wrapped in a
<figure>
tag - The
<figure>
tag may or may not have a<figcaption>
- The
<figure>
could include one<img>
or many - You want the images to fill the available width, but if there are multiple, shrink down to 25% for 4-columns
What I have here almost works ✅, but in cases with a figcaption and fewer than 4 images, the images don't fill the available width as I'd like ❌.
Help! See the example on CodePen.
Top comments (5)
I've also tried a flex based implementation. It avoids the main issue of the single image being too small with a caption, but it does mean any images on their own row fills the width. So, if you five images, four are 25% wide, and then the fifth is 100% on the next row. Not broken, but not my intention.
I'd try a grid area for the figcaption. Grid areas are placeholders for layout. If the thing isn't there, layout isn't rendered. If it is there it's rendered according to the area defs. Areas can be to assigned to be topmost, below, to the sides there can be any amount of areas. Truly a huge benefit to our layout needs.
Yeah, I did try a grid area, but I'm not sure how to (or if it is possible to) define a grid area that follows grid items placed implicitly (as there are an arbitrary number of img tags).
Thanks for the reply!
Ok here's what could work for you work for you Steven;
Example rendering
Thanks John. At this point your verging on doing free consulting work, which I don't want to take advantage of. Feel free to drop out of the conversation knowing you've been helpful.
That said, if you're still interested, or for anyone else following along, I don't think the named grid-area helps in this situation. The goal is for figures with only one or two images to have those images fill the full width.
For example instead of this:
I'm aiming for this: