You need to use display:none
to hide an element completely from the layout instead, which is documented as:
none - This value causes an element to not appear in the document. It has no effect on layout.
visibility:hidden
will leave an invisible box, which is the problem you are encountering. From the documentation:
hidden - The generated box is invisible (fully transparent, nothing is drawn), but still affects layout. Furthermore, descendants of the element will be visible if they have 'visibility: visible'.
The default CSS display
value for a <div>
is display:block
, so to show the <div>
again, just set the element back to display:block
. Note that there are other values for display
, so take care to set it back to it's original value (which might not necessarily be the default value).