1

So I have this jsfiddle:

https://jsfiddle.net/ionescho/4d07k799/4/

HTML:

<div class='container'>
<div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div><div class="row"></div>
</div>

CSS:

.container{
  line-height:0;
  width:100%;
}
.row{
  height:100px;  /* <--- try putting 100.66px here or some other fractional pixel value*/
  width:100.232323px;
  display:inline-block;
  background-color:red;
  border-bottom:1px solid black;
  border-right:1px solid black;
  line-height:0;
}

IF I apply a height of 100px to the class .row, I can see the border-bottom. If I apply a non-integer value to height( ex: 100.66px ), it disappears. Other times ( ex height: 100.22px ) it shows.

Is there a way to fix this? If for example I have a height expressed in percentage, it may resolve to a non-integer pixel height and then I will not see the border-bottom.

UPDATE: this happens only on CHROME!

ionescho
  • 1,360
  • 2
  • 17
  • 31

3 Answers3

4

You can use float: left; in place of display:inline-block;. It will work for any height.

vard
  • 4,057
  • 2
  • 26
  • 46
Abhinav
  • 156
  • 2
1

Browser can't render half pixel so it is doing approximation and your divs are collapsing eachother. If for some reason you need this height (?) you can compensate it by adding:

margin-bottom: .66px;

sample

side note - on hidpi screens (aka retina) your example with fractions is looking good. This is because each pixel in css has more than one pixel on display MDN devicePixelRatio

Damian Krawczyk
  • 2,241
  • 1
  • 18
  • 26
0

Abhinav give a good way.But you can do it by increasing border-bottom with respected height.You can check this in JSFIDDLE

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72