views:

433

answers:

2

Hi!

I hope to explain my problem simple in order to get good feedback :)

Imagine this scenario: One DIV wrapper within two floating DIVs, next to each other, with fixed width. All of them with overflow hidden.

But when decreasing the width of the wrapper (or increasing the children's) the last DIV collapsed instead of hide. Please, check out the code. THANK you very much in advance!

#wrapper{
 width:400px; 
 overflow:hidden;
 border:1px dashed #0033FF;  
}
#wrapper .tContent{
 width:210px; 
 height:200px; 
 float:left;
 overflow:hidden;  
}

 HTML:
<div id="wrapper">
<div class="tContent">
    <p>
        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
    </p>
</div>
  <div class="tContent">
 <p>
        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. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat        </p>
 </div>

How do you solve that? avoid the collapsing and keeping the floating and hiding if necessary?

+1  A: 

This is the expected behavior. You will need to add another div inside your wrapper with a fixed width large enough to accommodate both floats.

Example:

<div id="wrapper">
    <div class="wide">
        <div class="tContent">
        </div>
        <div class="tContent">
        </div>
    </div>
</div>

<script type="text/javascript">

    var total = 0;

    $(window).load(function() {

        $(".tContent").each(function(){ 
         total += $(this).width();
        });

        $(".wide").width(total);

    });
</script>
jeroen
Thank for your answer.My question now is, imagine the wrapper is 100% width but I've got enough children inside (floating next to each other) exceeding that width. They will collapse. Is there any way to reproduce the same overflow hidden effect as one div? Thanks!
Teknotica
I have read a solution somewhere here which was setting the children to display: inline-block but I could not get that to work on all browsers so I have used jQuery to dynamically set the width of the fixed width div (summing all widths of the children).
jeroen
OK, I will take a look then. Cheers :)
Teknotica
I found this jQuery plugin that works for what I want to do. I hope it works for someone else:http://welcome.totheinter.net/columnizer-jquery-plugin/
Teknotica
Interesting, although slightly unrelated to your original question ;-)
jeroen
Well, it solves what I want it to do: big pieces of text (floating divs) next to each other, even if they exceed the size of its parent. Look at the example #5 and you will see what I wanted
Teknotica
:) thank you!!!!
Teknotica
You´re right, it is basically the example I gave you where the width of the wide div is set to 3300px. It seems a bit overkill to use a plugin just to determine the width, I will add some jQuery to my example in case you want to do it yourself.
jeroen
It worked perfect! thank you!
Teknotica
A: 

The width of your both inner divs should not be bigger the the width of the wrapper. In order for this code to work, .tContent must have 200px width. Also, see this http://www.w3.org/TR/CSS2/box.html