I don’t understand the question.
If you have
display:none set nothing should show up including the child elements. That’s what it does.
Anyway, if it works in Codepen then the code is, logically, correct…so there must be something else going on on your site.
I’d suggest that THAT is what we need to see.