Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two elements inline block - no flow when resized

Tags:

css

I am looking for the best way to have multiple columns using inline-block. Everything works great except for when the browser is resized. The 2nd column will be pushed under the first column as one would expect with inline-block. I understand why that happens, what I need to know is if there is a way to make a horizontal scroll instead of pushing the second column down. I thought overflow:hidden would work, but it does not seem to.

I am not setting any widths right now and would like to keep this as fluid as possible.

<div>
    <div id="col1"></div>
    <div id="col2"></div>
</div>

col1 and col2 are inline-block with no width set and they display side by side when the browser view is wide enough. When the users browser is re-sized smaller, col2 displays underneath col1. I want them to always be side by side and have a horizontal scroll if needed.

like image 375
mcot Avatar asked Nov 11 '11 16:11

mcot


People also ask

Can inline elements be resized?

You can change the height of the inline-block meanwhile you can't change the inline elements.

How do I stop inline block wrapping?

As a result, the elements can sit next to each other. The major difference between display: inline; and display: inline-block; is that, display: inline-block; also allows us to set the width and height of the element. We can prevent inline-block divs from wrapping by adding suitable Bootstrap classes.

How are inline elements and block elements displayed out of normal flow?

In normal flow, inline elements display in the inline direction, that is in the direction words are displayed in a sentence according to the Writing Mode of the document. Block elements display one after the other, as paragraphs do in the Writing Mode of that document.


1 Answers

Add white-space: nowrap to the parent of the elements that have display: inline-block.

like image 107
thirtydot Avatar answered Sep 22 '22 12:09

thirtydot