{clear: both;} Meaning

Discussion in 'CSS' started by i_am_dhaval, Feb 14, 2012.

  1. #1
    When {clear: both;} is used ?

    What does “both” mean in <div style=“clear:both”> ?
     
    i_am_dhaval, Feb 14, 2012 IP
  2. simoncrequer

    simoncrequer Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    "clear" has three options:
    clear:left;
    clear:right; and
    clear:both;
    When you use clear:left, if you have any elements floated left before it, it will go under it instead of wrapping around it. clear:right does the same thing, but for elements floated right, and clear:both clears both left and right floated elements.
     
    simoncrequer, Feb 14, 2012 IP
  3. i_am_dhaval

    i_am_dhaval Well-Known Member

    Messages:
    1,364
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    138
    #3
    so it is like <span>?
     
    i_am_dhaval, Feb 14, 2012 IP
  4. i_am_dhaval

    i_am_dhaval Well-Known Member

    Messages:
    1,364
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    138
    #4
    can anyone give me small example how exert it will work.?
     
    i_am_dhaval, Feb 14, 2012 IP
  5. Alan Smith

    Alan Smith Active Member

    Messages:
    1,263
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #5
    Use of the HTML Div Tag is to layout your page. And Both mean in <div style=”clear:both;”></div> is No floating elements allowed on either the left or the right side. It can be used to clear the CSS float within a layout.
     
    Alan Smith, Feb 14, 2012 IP
  6. aircondition

    aircondition Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    use ?
    <div style="clear:both;"></div>
     
    aircondition, Feb 14, 2012 IP
  7. simoncrequer

    simoncrequer Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <div id="div1" style="float:left;"></div>
    <div id="div2" style="float:right;"></div>
    <div id="div3" style="clear:both;"></div>

    In this example, div3 will be under div1 and div2 (the floated elements) instead of trying to wrap around them, because it uses clear:both; If it didn't have clear:both; it would try and wrap around the first 2 divs.
     
    simoncrequer, Feb 14, 2012 IP
  8. themetribe

    themetribe Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    it's a way to create a new block after doing some floats before it.
     
    themetribe, Feb 15, 2012 IP
  9. spaculus

    spaculus Peon

    Messages:
    187
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #9
    {clear:both;} means it clear both float-right and float-left.
     
    spaculus, Feb 16, 2012 IP