TIL: CSS `display-contents`

The Problem

I’ve been playing around a lot with flexbox and css-grid in the last days. One of the problem that I commonly run into is when an element group has a wrapper and the wrapper is contained in a flex or a grid block. The easiest way to fix an issue like this is to assign the wrapper a display:flex (or grid). It’s really easy to do that, but whenever I do this, I hear sounds that says “It’s a hack”, “This is not clean”.

I generally have this issue when working on a WordPress theme or a template.

display-contents to the resuce

The solution to an issue like this is to add the style display:contents to the wrapper element. It makes the children appear to be direct children on the parent. The wrapper element will “disappear”.

Can I use ?

display:contentsis supported in number of browsers at the moment. MDN says its “experimental”. I say, go for it. I’ve been using this in cases where if it was not supported, the design would still not look ugly.

Webmentions

7/1/2020 ocn !$ replied Nice content* there 😂 I mistyped and my brain tricked me. on twitter
7/1/2020 Avinash replied haha i understand. From not writing anything this is a nice upgrade. Once i get into a regular habit of writing, i will start working on my content. Also, wasn't sure if there were any readers :D on twitter
7/1/2020 Avinash replied totally! once subgrid is complete and widely supported, number of layouts will be easier. I'd love to say "okay" when someone wants two rathar deep divs to be same in size :D on twitter
7/1/2020 Michael 🦀 replied That and ‘subgrid’ are welcome additions. on twitter
7/1/2020 ocn !$ replied Nice fontent there. I am a visual learner so first thing I looked for was inage or some snippet. Can you also please share snippet or add some image showing problem and solution. Thank you in advance. on twitter