SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Losing div borders because of floats inside it

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Losing div borders because of floats inside it

    Hi folks,

    I wonder if anyone can shed any light on why I'm losing left and right borders of these divs in IE when I have the elements inside floated?

    http://www.marketingmixers.com/direc...ncedsearch.php

    Any ideas?
    Last edited by aarpol; Jul 4, 2004 at 12:16. Reason: URL was wrong

  2. #2
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That URL gives a "page not found" error.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, fixed now.

    Any thoughts?

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?

  5. #5
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,872
    Mentioned
    103 Post(s)
    Tagged
    3 Thread(s)
    Haven't looked at the code yet but it looks like a position:relative is needed on the floats (or the parent - or both).

    I'll have a look at the code in a minute

    paul

  6. #6
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,872
    Mentioned
    103 Post(s)
    Tagged
    3 Thread(s)
    Hi,

    As suspected here is the offending code with the position:relative added:
    Code:
    div#content div {
    margin: 5px;
    padding: 0;
    border: 1px solid #000;
    clear: both;
    position:relative;
    }
    The borders will now appear as expected.

    You may wish to run your code through the validator as you have some invalid nesting in your code.

    Hope that helps.

    Paul

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fantastic thanks!

    Yeah, bound to be some validation errors in there at the minute. Will get them at the end.

    If you have a minute, could you explain why the position relative is necessary?

  8. #8
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,872
    Mentioned
    103 Post(s)
    Tagged
    3 Thread(s)
    If you have a minute, could you explain why the position relative is necessary?
    Yes - its a small bug in ie where it forgets whats in front and draws the background over the borders when it redraws. It sometimes will completely obscure floats and images (peek-a-boo bug).

    This usually happens on children of positioned elements so adding a positioning context such as position:relative forces ie to understand it better.

    Its a bug really but forcing a stacking context makes ie work it all out properly.

    Paul

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •