Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline-block elements within a fixed width container with overflow:hidden get pushed down

See my fiddle here: http://jsfiddle.net/Waterstraal/bMfbH/2/

The HTML:

<div class="row">
    <div class="actionPanel"></div><div class="resultPanel"></div>
</div>

The CSS:

.row {
    width:500px;
    height: 50px;
    overflow:hidden;
    border:1px solid #ccc;
}
.resultPanel {
    display:inline-block;
    width:450px;
    height: 50px;
    background: #ddd;
}
.actionPanel {
    display:inline-block;
    width:50px;
    height: 50px;
    background:#eee;
}

I want to "slide" the resultpanel to the right (so it's still on the same level as the actionPanel), but instead it gets pushed down out of view.

The width of the actionPanel is being made bigger in javascript so that the total width of the two elements are bigger than the width of the parent element.

Does anyone know how I can achieve the effect i'm after? I've tried to use floating elements, but that had the same result. I also tried to use a table element, to no effect.

Thank you in advance.

like image 845
Waterstraal Avatar asked Aug 01 '13 13:08

Waterstraal


People also ask

Do inline elements take up the entire width of their container?

In other words, inline elements do NOT start on a new line and only takes up as much width as its content. So, if you try to set any width and height, it will have NO effects.

Where do inline elements get their width and height?

Inline element properties: The height of an inline element is the height of the content. The width of an inline element is the width of the content. The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS.

What are the properties of inline block elements?

Inline-block elements are similar to inline elements, except they can have padding and margins added on all four sides. You'll have to declare display: inline-block in your CSS code. One common use for using inline-block is for creating navigation links horizontally, as shown below.

How do inline block elements add up to 100 width?

If you have a border or padding set for your divs, then you've created additional pixels that will prevent your divs from adding up to a 100% width. To fix this, make sure you've added box-sizing: border-box to the div's styles.


1 Answers

Add white-space: nowrap to the container of the inline-block elements, in this case .row.

http://jsfiddle.net/thirtydot/bMfbH/3/

like image 89
thirtydot Avatar answered Nov 10 '22 00:11

thirtydot