![](http://images-20200215.ebookreading.net/24/3/3/9781498731454/9781498731454__start-programming-using__9781498731454__bg71.png)
5.6 Hiding Elements
Professor: You can also take an element out of th e flow with the display property
set to none. Th is makes an element completely disappear from the page, while other
elements reposition themselves accordingly. Hiding part of the content is useful in
many ways. You can, for example, hide a portion of some long text and make it
accessible on ly on demand, or you c an hide a sub-menu of a navigation system and
make it visible only after the visitor has selected the corresponding top menu item.
Mike: How do you do that?
Professor: You put the removed element back in the flow by setting its display prop-
erty back to block or inline. You can allow the visitor to trigger that change either
through some JavaScript code or the :hover pseudo-class. We will cover pseudo-
classes later today.
Another way of hiding an element is by means of the vis ibility property, which
can be set to hidden or visible. Unlike the none value of the displa y property,
hiding an element through the hidden value of the visibility property leaves the
element in the flow and it only leaves an empty space where the element would have
been if it had not bee n hidden.
5.7 Flo ated Elements
Professor: Two more pro perties that control the eleme nt’s position are float and
clear. I guess that th e concept behind these two properties is one of the least intuitive
and henc e the most misun derstood concepts in CSS. I’ll try to illuminate the basics so
you have a firm foundation from which to study and explore the subject on your own.
You can flo at an element either to the left or right b y declaring float: left; or
float: ri ght; respectively. You cannot float an element to the center, th ough. Be-
cause the concept is basically the same for both floats, left and right, we’ll only focus
on left floats. So wha t happens if you float an element to the left?
• The floated element is first positione d according to its normal doc ument flow.
Then it is shifted horizo ntally all the way to the le ft until its left margin ed ge
touches the left edge of its containing block or the right margin edge of another
floated element. Technically, that takes th e element out of the flow, althoug h not
completely. Text and inline elements still respect its presence.
• All the conten t that appears ab ove the floated e le ment in the browser window is
unaffected .
• All text and inline elements that appear at the same h eight or below the floated
element flow alongside its right margin edge and wrap below it.
• Because the floated element is not in the flow, a ll the block elements position
themselves vertically as though the float didn’t exist. However, text and in-
line content of those block elements will reflow to make room for the floated
element.
5.6. Hiding Ele ments 85