1

I'm having a very simple problem which I can't overcome. I have a parent div, with 4 images inside, I would like the images to overflow from the parent div (horizontally) but I can't seem to achieve this.

.imgBanner {
   border: 1px solid black;
   width: 400px;
   height: 400px;
   display: inline-block;
}
.slideShow {
   width: 400px;
}
<div class="slideShow">
  <img class="imgBanner">
  <img class="imgBanner">
  <img class="imgBanner">
  <img class="imgBanner">
</div>

This is the code that I am using, but it doesn't seem to overflow, even though I am using display inline-block.

The outcome will be to hide the overflown images, and use JavaScript to create a slideshow.

EDIT: Forgot to add the fiddle. https://jsfiddle.net/pwL2hy7s/

Thanks :)

Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110
DevStacker
  • 675
  • 10
  • 23

2 Answers2

3

You can use

white-space: nowrap;

on the container. This will allow the elements to continue being inline, without being forced to break.

GMchris
  • 5,439
  • 4
  • 22
  • 40
1

I think this is exactly what you're tying to achieve. See the demo and comments inline below.

.slideShow {
  width: 400px;
  white-space: nowrap; /*prevent wrapping*/
  overflow: auto; /*show scrollbar as needed*/
  font-size: 0; /*remove whitespace*/
}
.imgBanner {
  background: aqua;
  width: 400px;
  height: 400px;
  display:inline-block;
  vertical-align: top;
}
.imgBanner:nth-child(odd) {
  background: gold;
}
<div class="slideShow">
  <div class="imgBanner"></div>
  <div class="imgBanner"></div>
  <div class="imgBanner"></div>
  <div class="imgBanner"></div>
</div>

Read more about the inline block whitespace at How to remove the space between inline-block elements?

Community
  • 1
  • 1
Stickers
  • 75,527
  • 23
  • 147
  • 186