9

I am trying to align two divs horizontally and I got it to work using display:inline-block however when I put overlfow-x:scroll to the main container it doesn't work. If the screen is smaller, one of the div goes to the bottom. How can I achieve this? I don't want the second Div to go to the bottom if the screen is small.

Here's fiddle

<div class="container">
<div class="test1">test1</div>
<div class="test2">test2</div>
</div>

.container{
display:table;
margin: 0 auto;
overflow-x:scroll;
}

.test1{
background-color:red;
 width:500px;
margin-left:16px;
display:inline-block;   


 }
.test2{
 margin-left:40px;
display:inline-block;
background-color:gray;
width:80px;

vertical-align:top;


}
3
  • 1
    Set fixed width to container Commented Aug 15, 2013 at 1:49
  • Updated: jsfiddle.net/f5HWD/1 Commented Aug 15, 2013 at 1:50
  • I believe 636px is the exact width for container like Avin said Commented Aug 15, 2013 at 1:54

3 Answers 3

8

give parameters to width and height, so container can overflow.

http://jsfiddle.net/f5HWD/3

.container{
    width: 900px;
    height: 700px;
    display:table;
    margin: 0 auto;
    overflow:scroll;
}
Sign up to request clarification or add additional context in comments.

3 Comments

@John: It is the general practice here on StackOverflow to not post an answer that has been suggested in the comments unless the OP asks the user to provide one because it was indeed the solution. MikelMax: If a user has provided a satisfactory answer in the comments ask them to give an answer so you can accept it. Taking points for another's answer is not encouraged
but this solution won't work when the screen size change? like if the page is opened on a cell phone.
@Martian2049 you can give percentage instead of pixel to achieve this jsfiddle.net/uh43p8cg
1

I altered your code slightly and made the contents float left.

In order you get it to work, you just had to create a wrapper class. You need the outside container to be large enough to just fit your test divs, while the wrapper is large enough to hold both combined. This should be fairly easy to figure out and edit according to the heights/widths that you want the divs to be.

Fiddle

Hope it helps.

Comments

0

In my case display flex is working.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.