What is Clear in CSS

Discussion in 'CSS' started by scripts, Sep 8, 2007.

  1. #1
    I want to know what is the purpose and meaning of clear in css? it has 3 available options: both, left or right . what does it mean.
    Please describe it if you know about it...
     
    scripts, Sep 8, 2007 IP
  2. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
  3. mikebrad0927

    mikebrad0927 Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    simply, it clears a float.
     
    mikebrad0927, Sep 8, 2007 IP
  4. veckd

    veckd Peon

    Messages:
    1,065
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This was hard for me to understand too. but lets say you use float to align two divs. One to the right and another to the left like this:
    <div style="float:left;width:400px;"></div><div style="float:right;width:400px;"></div>
    
    <div class="footer"></div>
    Code (markup):
    If you leave the code like that the footer will appear on top of the two floating divs. To fix this change the footer code to this:
    <div class="footer" style="clear:both;"></div>
    Code (markup):
    I hope that example helped
     
    veckd, Sep 8, 2007 IP
  5. tarponkeith

    tarponkeith Well-Known Member

    Messages:
    4,758
    Likes Received:
    279
    Best Answers:
    0
    Trophy Points:
    180
    #5
    Just like veckd said, it's usually (from what I've seen) used for footers and such to clear other "floating" div's..
     
    tarponkeith, Sep 8, 2007 IP
  6. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #6
    Don't know why one would apply a class of footer to a footer. And your example would be better off with height on the floating divisions.
     
    soulscratch, Sep 8, 2007 IP
  7. veckd

    veckd Peon

    Messages:
    1,065
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #7
    okay change it to id then...
     
    veckd, Sep 8, 2007 IP
  8. Rasczak

    Rasczak Peon

    Messages:
    131
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    helped me a lot too, thx;)
     
    Rasczak, Sep 10, 2007 IP
  9. RedMatrix

    RedMatrix Guest

    Messages:
    69
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You can also use "CLEAR: ALL"
     
    RedMatrix, Sep 11, 2007 IP
  10. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #10
    RedMatrix, not only are you using non standard or at best, ugly uppercase, but clear: all is not a valid value and you could have checked this yourself by looking at the link to the spec in the second post!
     
    krt, Sep 11, 2007 IP
  11. RedMatrix

    RedMatrix Guest

    Messages:
    69
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Did I say all? My bad, I meant both.
     
    RedMatrix, Sep 12, 2007 IP