Intro To Web Development With HTML/CSS 04: Advanced CSS, Part I Flow and Float
Intro To Web Development With HTML/CSS 04: Advanced CSS, Part I Flow and Float
Contents
1 Introducton
2 Positioning
2.1 Normal Flow
2.2 Out of flow .
2.2.1 Float .
2.2.2 Clear
1
. . . . . . . . . . . . . .
1 2.2 Out of flow
. . . . . . . . . . . . . .
1
. . . . . . . . . . . . . .
1 In normal flow, the position of an element is based on
. . . . . . . . . . . . . .
2 the elements defined before it in the HTML code. In
order to achieve positioning that is not in accord with
the normal flow (such as creating two divs and forcing
them to display side-by-side as columns rather than
1 Introducton
the second being below the first), we must break out
In the previous few documents, I have introduced of flow. This can be done through the use of CSS
HTML and CSS. In the previous document, CSS was float and position.
detailed as a tool to complement HTML in giving
HTML elements widths or heights, defining text colors and sizes, and so on. In other words, it was show- 2.2.1 Float
cased to be second place to HTML, so to speak. An HTML element can be assigned the CSS attribute
This was because I wanted to introduce the basic con- float, which has possible values of none (the decept of associating CSS rules with HTML elements, fault value), left, or right. (It can also be assigned
to show how they can work together.
inherit, but I have personally not found use for this
However, CSS has the ability to do much more than value.) If an element is floated left, its outer left
what was shown in the previous document. The topic edge (meaning that margin is accounted for) aligns
of this document is CSS positioning. This topic is with the left inner edge (meaning that padding is
complex enough to deserve individual attention. Be- accounted for) of its container, and analogously for
fore discussing the specific methods to position ele- float: right. The interesting aspect is that conments using CSS, however, we must be introduced to tent following a floated element is allowed to be posithe concept of flow.
tioned along the other side of that element, meaning
that an image (<img>) that is floated to the left that
is followed by text (in the code) will display with the
2 Positioning
image flush to the left of the containing element with
the text to the right of the image, instead of below it
2.1 Normal Flow
as would normally happen with a block type element.
Recall the distinction between block and inline el- It will also be displayed as high as possible within its
ements. Block type elements, such as <div>, are parent element.
placed on their own line within their containing elHere is an example of a div floated to the left, folement and, by default, are followed by a new line, so lowed in the HTML code by text:
1
Clear