Marty.H
Marty.H

Reputation: 1204

Make inline-blocks stretch container horizontally

I want to make it so if the inline blocks inside a container exceed the width of the container they make it stretch rather than dropping down below.

I made a codepen of what I mean: http://codepen.io/anon/pen/pJQWbR

<div class="container">
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
</div>

css

.container{
  overflow: scroll;
}

.content{
  height: 100px;
  margin: 5px;
  background: blue;
  display: inline-block;
  width: 25%;
}

Trying to make the blue boxes all be on one line.

Upvotes: 2

Views: 624

Answers (2)

Try this one. Just change the width of .content class.

.container{
  overflow: scroll;
}

.content{
  height: 100px;
  margin: 5px;
  background: blue;
  display: inline-block;
  width: 17%;
}
<div class="container">
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
</div>

Upvotes: 0

Nikhil Batra
Nikhil Batra

Reputation: 3148

Add

white-space: nowrap

to the container

So container style becomes:

.container{
  overflow-x: scroll;
  white-space: nowrap;
}

white-space: nowrap means Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a < br > tag is encountered

See the link : "http://codepen.io/anon/pen/xGQXRz"

Upvotes: 3

Related Questions