Elements can be visible even though their parent has set "visibility: hidden" (#tilPost)

Responsive design can be a real challenge if you’re coding something that needs more than just squishing and reordering some boxes. Scott O’Hara published an article describing how to build elements that act as buttons or spans depe…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Responsive design can be a real challenge if you're coding something that needs more than just squishing and reordering some boxes. Scott O'Hara published an article describing how to build elements that act as buttons or spans depending on the viewport size.

The trick: Scott uses CSS visibility to hide and show elements throughout the element tree conditionally.

<!-- Hide the button on smaller viewports 
     and only show the span -->
<button type="button">
  <span>Do something</spin>
</button>

Wait what? As it turns out, nested elements with different visibility properties (visible / hidden) can be visible even though their parent is hidden. 😲

Here's the MDN section about this topic.

Descendants of the element will be visible if they have visibility set to visible.

That's pretty wild!

[Interactive component: visit the article to see it...]

I'm not sure yet, what to make of this discovery. Scott's responsive pattern seems incredibly smart but also super hacky. I guess I have to sleep over it...


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2022-11-24T23:00:00+00:00) Elements can be visible even though their parent has set "visibility: hidden" (#tilPost). Retrieved from https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/

MLA
" » Elements can be visible even though their parent has set "visibility: hidden" (#tilPost)." Stefan Judis | Sciencx - Thursday November 24, 2022, https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/
HARVARD
Stefan Judis | Sciencx Thursday November 24, 2022 » Elements can be visible even though their parent has set "visibility: hidden" (#tilPost)., viewed ,<https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » Elements can be visible even though their parent has set "visibility: hidden" (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/
CHICAGO
" » Elements can be visible even though their parent has set "visibility: hidden" (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/
IEEE
" » Elements can be visible even though their parent has set "visibility: hidden" (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/. [Accessed: ]
rf:citation
» Elements can be visible even though their parent has set "visibility: hidden" (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2022/11/24/elements-can-be-visible-even-though-their-parent-has-set-visibility-hidden-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.