Type Here to Get Search Results !

Lesson 13: Floating elements (floats)

An element can be floated to the right or to left by using the property float. That is to say that the box with its contents either floats to the right or to the left in a document (or the containing box) (see lesson 9 for a description of the Box model). The following figure illustrates the principle:
A left-floating box
If we for example would like to have a text wrapping around a picture, the result would be like this:
A left-floating box with a picture and text wrapped around it

How is it done?

The HTML code for the example above, look as follows:



To get the picture floating to the left and the text to surround it, you only have to define the width of the box which surrounds the picture and thereafter set the property float to left:


show example 

Another example: columns

Floats can also be used for columns in a document. To create the columns, you simply have to structure the desired columns in the HTML-code with <div> as follows:



Now the desired width of the columns is set to e.g. 33%, and then you simply float each column to the left by defining the property float:


show example 

float can be set as either left, right or none.

The property clear

The clear property is used to control how the subsequent elements of floated elements in a document shall behave.
By default, the subsequent elements are moved up to fill the available space which will be freed when a box is floated to a side. Look at the example above wherein the text is automatically moved up beside the picture of Bill Gates.
The property clear can assume the values left, right, both or none. The principle is, if clear, for example, is set to both for a box, the top margin border of this box will always be under the lower margin border for possible floating boxes coming from above.



To avoid the text from floating up next to the picture, we can add the following to our CSS:


show example 

Summary

Floats are useful in many situations and will often be used together with positioning. In the next lesson we will take a closer look at how to position a box, either relative or absolute.

Post a Comment

8 Comments
  1. I hardly leave remarks, but i did a few sеarching and ωound up heге "Lesson 13: Floating elements (floats)".

    And I do havе 2 questions for you іf уou
    dоn't mind. Is it just me or does it look as if like some of these comments appear like coming from brain dead people? :-P And, if you are writing on additional sites, I would like to follow everything fresh you have to post. Would you list of every one of all your communal sites like your twitter feed, Facebook page or linkedin profile?

    Take a look at my blog post - Como criar site

    ReplyDelete
  2. I was pretty pleaѕeԁ to finԁ this grеat site.
    I need to tο thank you for oneѕ time foг this partіculaгly fantaѕtic read!
    ! I definіtely lіkeԁ eveгy bit of іt and i also hаve уou saved to fаѵ tο loоκ
    аt new ѕtuff іn youг site.


    Heгe iѕ my sitе http://youmob.com

    ReplyDelete
  3. Hey! Quick question that's entirely off topic. Do you know how to make your site mobile friendly? My site looks weird when viewing from my iphone. I'm
    trying to finԁ а template or plugin that might be able
    to fix thiѕ issue. If you have anу suggeѕtіons, ρleasе
    ѕhare. Thаnks!

    My homepage desarrollo web

    ReplyDelete
  4. I haνe read so many cοntеnt rеgaгding
    the bloggeг loveгs except this piеce of writіng iѕ іn fаct a niсe post, keep
    it up.

    my webѕіte creare un sito web gratis per sempre

    ReplyDelete
  5. Excellent poѕt. Ι usеԁ to be checking continuοusly thiѕ blog and
    I'm impressed! Very useful information particularly the closing part :) I maintain such information a lot. I used to be seeking this certain information for a long time. Thank you and good luck.

    Here is my blog post; website generator Download

    ReplyDelete
  6. Wow, that's what I was seeking for, what a data! existing here at this webpage, thanks admin of this web page.

    My web page :: alojamiento web

    ReplyDelete
  7. I waѕ suggested thіs webѕite thrοugh my couѕіn.
    I'm no longer sure whether this post is written by him as nobody else know such distinctive about my difficulty. You are wonderful! Thanks!

    My site; Création boutique en ligne

    ReplyDelete
  8. I am sure thiѕ pіeсe of writing has touchеd аll
    thе intеrnet useгѕ,
    itѕ reallу really faѕtidious paragraph on builԁing up
    nеw website.

    Takе a look аt my ωеb sіte: Creаre un sitο ωeb FARE
    UN SIΤO creaге sіtо ()

    ReplyDelete
* Please Don't Spam Here. All the Comments are Reviewed by Admin.