This is the eighth part in my CSS Styling tutorials, in which I will be covering floating.
What is Float?
Float is used to make an element act as a lightweight object which can fit in white space and therefore removes its aligning to center and such like.
The use of float is to essentially make an element inline display with other elements which are already inline displayed or also have a float. Float can be used in places such as navigation bar links, gallery image thumbnails and columns of information.
Clear is also used in conjunction with Float which can be used to specify where other floating elements are not allowed. For example; if you have three images floating left, the second image can clear right meaning the third image would be forced underneath.
Values - Float:
left - Floats the element to the left.
right - Floats right.
none - Removes all float values.
inherit - Specifies that the value of the float property should be inherited from the parent element.
Values - Clear:
left - Clears the left side of the given element.
right - Clears the right side of the given element.
both - Clears both sides.
none - Removes all clear values.
inherit - Specifies that the value of the clear property should be inherited from the parent element.
Linking CSS To a HTML Element:
To link your CSS to an HTML element (text, div, etc.) you will need to decide whether you want to use a class or id, you will also need a unique name. Once you have those, go to your element in HTML and add...
... to the attributes of that element if you chose a class, or...
if you chose an id.
Make sure you replace 'myClass' and/or 'myID' with your unique name. Then, in the CSS you will want to encase your properties with...
//Properties go here
if you chose a class, or...
//Properties go here
(You can remove the line beginning with // if you wish).
Here's an example...
// Floats left.
// Clears both sides to force the rest of the divs underneath.
// Floats right.
// Removes float.
<div class='left'>Floating left...</div>
<div class='right'>Floating right...</div>
<div class='none'>All floats are removed.</div>