Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 2 months ago

Bento grid Layout (Grid and Flexbox)

Michael Okwuosah•90
@michaelo-o
A solution to the Bento grid challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What challenges did you encounter, and how did you overcome them?

One of the main challenges was managing the grid layout using grid-template-areas, especially when working with overlapping elements and irregular tile sizes. It was tricky to visualise how the areas would behave on different screen sizes, and a single mistake—like having the wrong number of columns in a row—would break the entire layout and trigger a grid-template-areas: invalid property value error in the browser.

Another significant challenge was making one grid item (Item 2) shorter without breaking the layout, while ensuring that other items (like Items 5 and 6) would move up to fill the freed space. CSS Grid doesn’t naturally support masonry-style stacking, so achieving that "irregular layout" aesthetic required careful use of grid-row, align-self, and negative margins — though even then, full masonry behaviour wasn't possible.

I also faced a situation where my media queries were being ignored or marked as invalid. After some inspection, I discovered it was caused by a typo and mismatched values in grid-template-areas, where the number of columns didn’t match across rows. Fixing the column count and simplifying the media query logic resolved the issue.

How I Overcame Them Grid Debugging: I relied heavily on browser DevTools to inspect grid overlays and confirm how many columns each row spanned. This helped catch syntax issues in grid-template-areas quickly.

Step-by-Step Isolation: I broke the grid down into smaller test cases to verify each row's layout before building the full structure. This modular approach helped pinpoint where layout issues were introduced.

Fallback to Flexbox & Negative Margins: Since CSS Grid couldn't fully emulate the masonry-style stacking I was after, I used negative margins on Items 5 and 6 and limited Item 2's height with align-self: start to create the illusion of vertical imbalance, preserving the visual style.

What specific areas of your project would you like help with? What Specific Areas of My Project Would I Like Help With?

One area I’d like help with is creating a more authentic masonry-style layout using only CSS Grid. While I managed to simulate the effect with negative margins and fixed heights, I’d love to learn if there are cleaner, more scalable methods — especially ones that don’t require JavaScript or hardcoded values.

Another area is improving the responsiveness of the grid at mid-range breakpoints (between desktop and mobile). While my media queries work well on very wide or very narrow screens, layouts around 900–1100px still feel a bit cramped or uneven. Guidance on fluid responsive strategies or more dynamic grid setups (possibly using minmax() or auto-fit) would be helpful.

Lastly, I’d appreciate suggestions on simplifying and optimizing my media queries. With several breakpoints and many duplicated style overrides, the CSS is getting bulky. If there’s a more elegant way to handle these size transitions while maintaining visual balance, I’d love to implement it.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Michael Okwuosah's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License