1

I'm running into an issue where I cannot remove the spaces between divs. I've included my markup and css and a fiddle: http://jsfiddle.net/kW5uW/12/

Despite having set margin and padding to zero, I still see spaces in between the divs, how can I remove this? I want all the boxes to be right next to each other.

CSS and Markup:

.segment {
  width: 20px;
  height: 20px;
  background: grey;
  border: 1px solid black;
  display: inline-block;
  padding: 0px;
  margin: 0px;
}

.container {
  padding: 0px;
  margin: 0px;
}
<div class="container">
  <div class="segment"></div>
  <div class="segment"></div>
  <div class="segment"></div>
  <div class="segment"></div>
  <div class="segment"></div>
</div>

Any advice would be appreciated. Thanks.

captainsac
  • 2,484
  • 3
  • 27
  • 48
link
  • 2,480
  • 1
  • 16
  • 18

2 Answers2

11

Inline elements are sensitive to white space. One way to fix this is to just remove the white space between the divs:

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

jsFiddle example

You could also:

j08691
  • 204,283
  • 31
  • 260
  • 272
0

I was able to fix this, by changing your segment class CSS to the following:

.segment {
    width: 20px;
    height: 20px;
    background: grey;
    border: 1px solid black;
    display: block;
    float: left;
    padding: 0px;
    margin: 0px;
}
captainsac
  • 2,484
  • 3
  • 27
  • 48
alanine
  • 121
  • 5