/blog/articles/

Make an element inside a hidden element visible with CSS

Let's imagine the following scenario: You have an element that should be hidden but one of the elements inside it should be visible. I'm sure everyone has had this problem before and tried to force it with opacity. At least I did. But that's not possible. As soon as you set an element to opacity: 0; all of it's children will forever be invisible.

I'm not visible I'm not visible

See the Pen uLJEx by Martin Wolf (@martinwolf) on CodePen.

Same with display: none;. You can't set a children back to display: block;.

See the Pen rnFam by Martin Wolf (@martinwolf) on CodePen.

But a while back I learned that visibility actually behaves differently. You can set visibility: hidden; for a parent element and show a children element with visibility: visible.

I'm not visible I'm visible

See the Pen IyEeb by Martin Wolf (@martinwolf) on CodePen.

Hope this helps!

Martin Wolf

Hi, I’m Martin Wolf, a Freelance Frontend Web Developer from Germany.
I believe in hard work and sharing what I know.

Contact me

Interested in working with me? Fantastic! The best way to get in touch is by email (hello@martinwolf.org). I’m looking forward to hearing from you.