Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: How to create a series of div on one line hiding the overflowing divs

I have a site built with bootstrap and I want to create a table with swipeable header using the jquery.dragscroll plugin but preserving the fluid grid built-in bootstrap.

So I want to create the headers of the table, and I am using this HTML:

<div class="row-fluid">
    <div class="span12">
        <div style="overflow:hidden;width:90%;">
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
            <div style="display:inline-block;width:100px">some content</div>
        </div>
    </div>
</div>

The code is here: http://jsfiddle.net/cVfzJ/1/

As we can see in the Fiddle all the divs are visible on two rows, my objective is to have all the divs on a single row (hiding the overflowing divs)

I hope the question is clear

like image 815
Mangiucugna Avatar asked May 27 '13 13:05

Mangiucugna


People also ask

How do I display div content on one line?

You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.

How do I show all divs on the same line?

By default, if we have multiple div tags it will be displayed one below the other. In othere words, each div will be displayed in a separate line. To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values.

How do I keep my div from wrapping to the next line?

If you want to prevent them from wrapping, either remove the white space you have used for formatting, or add white-space:nowrap; to the rule for .


1 Answers

You should have a container for all the <div> that has width equal to the sum of all <div>. Then the parent of this container has to have overflow: auto.

If you don't know the total width prior to the render you can use JS to calculate it.

Continuing your example:

<div class="row-fluid">
    <div class="span12">

        <!-- Changed from `hidden` to `auto`. -->
        <div style="overflow:auto;width:90%;">

            <!-- This is the div that does the trick: -->
            <div style="width:1200px;">

            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>
            <div style="display:inline-block;width:100px;">some content</div>

            </div>

        </div>
    </div>
</div>
like image 76
Arthur Corenzan Avatar answered Nov 03 '22 02:11

Arthur Corenzan