I'm trying to build a slider, but I'm trying to make all the li elements on one line. So far I have this fiddle to show what I'm doing:
My HTML:
<div class="carousel">
<ul style="width: 654px;" class="slides">
<li class="slide">
<div class="img-wrapper">
<img src="assets/img/agouti-teeth.png" alt="Agouti Teeth">
</div>
<div class="caption">Agouti Teeth</div>
</li>
<li class="slide">
<div class="img-wrapper">
<img src="assets/img/chipmunk-tail.png" alt="Chipmunk Tail">
</div>
<div class="caption">Chipmunk Tail</div>
</li>
<li class="slide">
<div class="img-wrapper">
<img src="assets/img/birds-nest.png" alt="Bird's Nest">
</div>
<div class="caption">Bird's Nest</div>
</li>
<li class="slide">
<div class="img-wrapper">
<img src="assets/img/agouti-teeth.png" alt="Agouti Teeth">
</div>
<div class="caption">Agouti Teeth</div>
</li>
<li class="slide">
<div class="img-wrapper">
<img src="assets/img/chipmunk-tail.png" alt="Chipmunk Tail">
</div>
<div class="caption">Chipmunk Tail</div>
</li>
<li class="slide">
<div class="img-wrapper">
<img src="assets/img/birds-nest.png" alt="Bird's Nest">
</div>
<div class="caption">Bird's Nest</div>
</li>
</ul>
</div>
My CSS:
.carousel {
position: relative;
overflow: hidden;
}
.carousel .slides {
list-style: none;
overflow: hidden;
padding: 0;
margin: 0;
}
.carousel .slides .slide {
display: inline-block;
background-color: #F0F0F0;
margin: 0 2px;
width: 105px;
}
.carousel .slides .slide .caption {
background-color: #D0D0D0;
text-align: center;
}
Each slide is 105 pixels in width with a 2 pixel margin on the left and right side of it. So the math I did was 105 x 6 (6 slides). This gave me 630 pixels. With the slide margins, it has a total of 4 pixels for the right and left together. So I did 4 x 6 which equals 24. Then added them together. 630 + 24 = 654 pixels. I thought my programming was off, but it's the same either way. But for some odd reason it will only go on one line if the width is 671 pixels (17 greater). I tried a width of 110 pixels for each slide, but then the container (following the same math) had to have 20 extra pixels. So it changes over time so I can't just add 17 pixels randomly for my equation.
I'm not sure what's going on. Thanks for any help!