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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.