resizing page when content is hidden

When a text box is filled with more text, the page automatically resizes, great. How can I achieve the same end result in a situation where a text box contains no text and as a result I wish to hide the box and the heading I have over that text box?

Currently I can hide them automatically, but it is leaving a large blank space on the page.

To avoid the blank space —> use collapse and expand-commands.

collapse —> lets collapsing an element
expand —> expands an collapsed element

When you use just hide or show, this also will just hide or show the element, it gets invisible, but the element is still on place.