Problem with div background and floats

Discussion in 'CSS' started by muiomuio, Oct 23, 2008.

  1. #1
    I have the div #content with #sidebar and #conteudo inside of it.

    With no floats the layout works perfectly, when I give a float to #conteudo the #content div disapears and the layout breaks completly with #conteuto going over the rest of the layout, #footer included.

    <div id="content">
    <div id="sidebar">
    <h2>Menu</h2>
    <div class="menu">
    <ul><li>Item 1</li>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
    <li>Item 4</li>
    <li>Item 5</li>
    <li>Item 6</li></ul>
    </div><!-- menu -->
    <div class="menu_bottom"></div><!-- fundo menu -->
    </div>
    <!-- sidebar -->
    
    <div id="conteudo">
    <div class="entry">
    <h1>Apresentação</h1>
    <div class="info">22 setembro 2008</div>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div><!-- entry -->
    </div><!-- conteudo -->
    
    </div><!-- content -->
    Code (markup):
    I checked the code and haven't found any unclosed tags.
    The CSS even with simple width and float attributes will break as soon as #conteudo gets a float.

    Have you ever had this problem? Do you know why it happens? How can I fix this?

    An image of the problem is attached.
     

    Attached Files:

    muiomuio, Oct 23, 2008 IP
  2. webdesigner

    webdesigner Well-Known Member

    Messages:
    489
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #2
    If you give something a float - it floats, and other content can go beneath it.

    So for example, if we had:

    a header - normal div
    a sidebar div floated left
    content also floated left
    normal div footer

    In the above case, the footer would go beneath the sidebar and content because they are floating. You can get around this by giving your footer a style of clear:left; or clear:right; or clear:both;
     
    webdesigner, Oct 24, 2008 IP
  3. muiomuio

    muiomuio Active Member

    Messages:
    225
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    83
    #3
    Yes you are right and I completly forgot to do the clear:both on the footer.

    But even after doing that the #content background still doesn't show when i put a float on to #conteudo
     
    muiomuio, Oct 24, 2008 IP
  4. webdesigner

    webdesigner Well-Known Member

    Messages:
    489
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Can you provide a link?
     
    webdesigner, Oct 24, 2008 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you post the CSS in relation to the code above then we can help as this error is obviously CSS related.

    It sounds as if you aren't clearing your floats.

    Add float: left; to your #content inside your CSS and see if that fixes the background issue.
     
    wd_2k6, Oct 24, 2008 IP
  6. muiomuio

    muiomuio Active Member

    Messages:
    225
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    83
    #6
    Hey, thanks alot, the float:left did the job.

    But any explanation for this?
     
    muiomuio, Oct 24, 2008 IP
  7. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #7
    wd_2k6, Oct 24, 2008 IP