Results 1 to 6 of 6

Thread: outer <div>(s) not expanding to fit float <div>

  1. #1
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default outer <div>(s) not expanding to fit float <div>

    I have this series of outer <div> elements used to create a nice rounded edge border look but once I add a float element inside then the outer <div> elements act as if nothing is there. I understand that the parent <div> is supposed to ignore any float. My question is how to make the outer <div> fit to the size of the inner float <div>
    Here is a sample:

    Code:
    ***CSS File***
    .b {background: url(images-jpgs/dot.jpg) 0 100% repeat-x}
    	.l {background: url(images-jpgs/dot.jpg) 0 0 repeat-y}
    	.r {background: url(images-jpgs/dot.jpg) 100% 0 repeat-y}
    	.t {background: url(images-jpgs/dot.jpg) 0 0 repeat-x;}
    	.bl {background: url(images-jpgs/bl.jpg) 0 100% no-repeat}
    	.br {background: url(images-jpgs/br.jpg) 100% 100% no-repeat}
    	.tl {background: url(images-jpgs/tl.jpg) 0 0 no-repeat}
    	.tr {background: url(images-jpgs/tr.jpg) 100% 0 no-repeat; padding:10px;}
    
    
    *** HTML File ***
    <div style="float:left;margin:3% 0% 0% 30%;width:30%;">
    <div class="t"><div class="b"><div class="l"><div class="r">
    <div class="bl"><div class="br"><div class="tl"><div class="tr">
    <div style="float:left;margin:2% 0% 0% 5%;">
    BlahBlahBlahBlah
    BlahBlahBlahBlah
    BlahBlahBlahBlah
    </div>
    </div></div></div></div></div></div></div></div>
    </div>
    Thanks in advance for any help.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You need to include an empty division with the style:

    clear:left;

    below any floats and as the last item within a container that you want to expand to the size of the left float(s):

    Code:
    <div style="float:left;margin:3&#37; 0% 0% 30%;width:30%;">
    <div class="t"><div class="b"><div class="l"><div class="r">
    <div class="bl"><div class="br"><div class="tl"><div class="tr">
    <div style="float:left;margin:2% 0% 0% 5%;">
    BlahBlahBlahBlah
    BlahBlahBlahBlah
    BlahBlahBlahBlah
    </div>
    <div style="clear:left;"></div>
    </div></div></div></div></div></div></div></div>
    </div>
    At least that is one place it could go. Hard to say for sure. Just put it after the last float that you want to make fill out its container.

    If you were floating right, you would clear:right;. If floating in both directions, you would clear:both;.

    However, since your corners depend upon floating, you may not be able to do this without messing them up. If so, consider using another method of of positioning the content.
    Last edited by jscheuer1; 08-14-2007 at 04:07 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll give it a whirl...thx John.

  4. #4
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it seems to work....thx again.
    This might be asking too much but how exactly did that fix the problem?

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    No, not at all. You see, when you float something it has native height, but by virtue of being floated is taken out of the flow of the page, that's why it floats. It is a little like position absolute, which also has native height, but is out of the flow of the page. With absolute positioning though, there is no way to resume the natural flow of the page short of giving it a container, but then the height is that of the container. With floats however, we have the clear property. What that does is to make sure that the element with the clear property is below the float, it clears it in the same way that a pilot with enough altitude clears a mountain top, only turned upside down. If that (clear) element isn't floating, the normal flow of the page will be restored below it as well.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    that makes sense...thx again.

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
  •