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>
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.
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.
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.
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;
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With