mentalist Posted April 23, 2009 Share Posted April 23, 2009 Hi, I could swear that what i'm after was default behaviour... Basically I have a div wrapping some other divs, but it won't stretch to wrap around them. <html> <head> <style type='text/css'> .box_wrap{ background-color: #efefef; border: 1px solid #ff0000; padding:3px; } .box_one, .box_two, .box_three{ position:relative; background-color: #aaefef; border: 1px solid #000000; float:left; padding:3px; } </style> </head> <body> <div class='box_wrap'> <div class='box_one'>One</div> <div class='box_two'>Two</div> <div class='box_three'>Three</div> </div> </body> </html> How do I get 'box_wrap' to stretch to wrap? Cheers! Quote Link to comment Share on other sites More sharing options...
jcombs_31 Posted April 23, 2009 Share Posted April 23, 2009 The problem is related to the float. you can always try the clearfix css hack or apply a width and overflow attribute to your wrapper div. http://www.positioniseverything.net/easyclearing.html Quote Link to comment Share on other sites More sharing options...
mentalist Posted April 23, 2009 Author Share Posted April 23, 2009 Hi, That's very good thanks, it sort of solves the problem... Now it's the width, it fills the whole width and not just the width of the containing elements. Any ideas? Cheers... Quote Link to comment Share on other sites More sharing options...
jcombs_31 Posted April 23, 2009 Share Posted April 23, 2009 I'm not sure I follow, you haven't declared a width for your wrapper. Quote Link to comment Share on other sites More sharing options...
mentalist Posted April 23, 2009 Author Share Posted April 23, 2009 no, that's right. I'd like it to snugly wrap the inner contents, which will be dynamically generated, so size is unknown, well sometimes it'll contain 3 elements, others 5, but they can vary in content, (it's for pagination). Quote Link to comment Share on other sites More sharing options...
jcombs_31 Posted April 23, 2009 Share Posted April 23, 2009 By default a div is a block level element so it will fit your window width. Quote Link to comment Share on other sites More sharing options...
mentalist Posted April 23, 2009 Author Share Posted April 23, 2009 So there's no way to make the width as small as possible for a dynamic element. As usual i've fallen back to html, wrapped it in a table and hey presto, exactly what I want... But i'm not supposed to be using tables... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.