Elements can be hidden from view with the visibility property. Why would someone choose to hide an element? If I don’t want it to be shown, shouldn’t I use the block comment /* instead?
Much of what we access on the web today is dynamic in nature, that means immediate change in view occurs with every listened for event. Take for instance a menu that is out of sight until the user hovers on a hamburger icon, then pops into view.
Mind, this would not be a use for visibility but display. The latter takes the object completely out of normal flow, the former does not.
visibility applies to a defined object and does not alter its position in normal flow. If it has dimensions, it will take up space, whether visible or hidden. Where this comes into play is when we have a defined layout and we don’t want it jumping around, but stable, with everything maintaining its position.
Say for instance our code displays messages at various intervals or upon given events and outcomes that we don’t want to display for very long. Popping in a message will cause the lines below that point to shift in order to make room for the message to fit in. visibility protects the real estate that message needs to display. When the message is gone, the space remains, but is unoccupied.
will hide the textContent but will not give up the line. Mind, we can still collapse if we so desire. In either case, we do not manipulate the textContent. It gets set elsewhere.
Seems that it is! I’ve searched further and found a solution. I needed to apply the hidden rule not on the element or a container, but on the element inside a container, and than to apply :hover pseudoclass on a container itself. After all, this code works fine:
The property is meant for small regions of the page, not wholesale real estate. Given three divisions with equal spacing around them within a parent container, having one visibility: collapse with remove that div and use the shared space between the remaining two. Collapse one more and that space is given over to the remaining div.
Using visibility: hide in that context will not give up the space of the hidden element, so will be blank until the element is restored.
What is the difference between the visibility: hidden and visibility: collapse. Both of them when applied hides the element from the webpage, but reserves the space.
How does visibility: collapse differ from display: none please?
Using your example, with visibility: collapse, the parent container would remain the same size (with the extra space shared between the other two divs)…but display: none would cause the parent container to shrink and only take up enough space to display the two remaining divs? Is that it?
Otherwise I’m still struggling to understand the difference between the two other than using the former for small regions of the page and the latter for “wholesale real estate” (ha!). Thanks for your help!