tags:

views:

38

answers:

5

I have some DIVs with contents inside. I want to display them side by side and if there is no space, I want to break the whole div, so the contents don't go to a new line alone.

I've made this example of what happens.

Here is a screenshot from the link above.

csspos

And here is the expected output

cssposright

+3  A: 

How about http://jsfiddle.net/qB225/15/? That adds

.item {
    ...
    white-space: nowrap;
}
MvanGeest
I'm seeing 3 links on the first row, then 1 on the second row.
meder
That's possible. The question was, however, not to equally distribute these texts. The question was about wrapping.
MvanGeest
Agreed. That's another question, and the user doesn't specify whether he wants `overflow: auto` or `overflow: none`.
MvanGeest
A: 

http://jsfiddle.net/qB225/21/

.master
{
    width: 160px;
}

.item
{
    display:inline-block;
    font-size: 11px;
    padding: 2px 2px 2px 0;
}

.item { display:inline; } /* DO NOT REMOVE, FOR IE */

.item a
{
    text-transform: uppercase;
}
​
meder
Change the right padding to 12 and you will see it doesn't work.
BrunoLM
+1  A: 

Put non-breaking space between your links and spans.

http://jsfiddle.net/qB225/22/

Sorcy
A: 

If you want them to only wrap as pairs you need to do two things. First change your html so that you group your item divs in pairs of two:

<div class="master">
    <div>
        <div class="item">
            <a href="javascript:;">Text</a>
            <span>(10)</span>
        </div>
        <div class="item">
            <a href="javascript:;">Text</a>
            <span>(10)</span>
        </div>
    </div>
    <div>
        <div class="item">
            <a href="javascript:;">Text</a>
            <span>(10)</span>
        </div>
        <div class="item">
            <a href="javascript:;">Text</a>
            <span>(10)</span>
        </div>
    </div>
</div>

And then add a float to the grouping divs:

.master > div{ float:left; }
Matthew Manela
A: 

Try using "inline-block" as follows:

.item
{
  display: inline-block;
  font-size: 11px;
  padding: 2px 2px 2px 0;
}

Thanks.

Hoque