Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inline divs with hidden overflow

I want to create 3 divs side by side when only one of them is visible.

-------------- -------------- --------------
| visible    | | invisible  | | invisible  |
|            | |            | |            |
-------------- -------------- --------------

In order to do this I have tried to create a wrapping div with a 100px width, and hidden overflow. What am I doing wrong?

<div style="width:50px;height:349px; overflow:hidden">
<div style="display: inline;">first div</div>
<div style="display: inline;">second div</div>
<div style="display: inline;">third div</div>
</div>
like image 847
Jim Avatar asked Jan 16 '11 12:01

Jim


People also ask

How to make div not break line?

Set size and make inline Because they're block elements, when reducing the size of Div one to make room for the other div, you're left with space next to Div one and Div two below Div one. To move the div up to the next line both div's need to have the inline-block display setting as shown below.

What is overflow inline?

The overflow-inline CSS property sets what shows when content overflows the inline start and end edges of a box. This may be nothing, a scroll bar, or the overflow content. Note: The overflow-inline property maps to overflow-y or overflow-x depending on the writing mode of the document.

How to show two div in same line?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.


2 Answers

display: inline doesn't let you set width. You should use display: inline-block instead.

Cross-browser issues:

  • This won't work properly with IE, which only allows inline-block on naturally inline elements, such as <span>s, so you can either convert the <div>s into <span>s or, use an IE hack: display:inline-block; zoom:1; *display:inline;

  • And for Firefox v2 and lower, you'll need display: -moz-inline-stack;.

like image 87
David Tang Avatar answered Nov 02 '22 04:11

David Tang


You have to make the wrapping div big enough (in width) to hold all three of the divs. Then you could wrap another div around that with the overflow hidden.

like image 37
Paul Avatar answered Nov 02 '22 03:11

Paul