Chrome shows thin line if table has TD background image

Viewed 1050

I have table with cells (td) with background images, on both mobile and desktop chrome it shows thin line between TD if table's absolute position is not aligned to round pixels.

// in case you don't see the glitch at 0.5px
var f = 0;
window.onclick = function() {
  f += 0.3;
  document.body.style.paddingLeft = f + 'px';
  document.body.style.paddingTop = f + 'px';
};
body {
  background-color: white;
  padding-left: 0.5px;
  padding-top: 0.5px;
}

table {
  border: 0;
  border-collapse: collapse;
}

table.image td {
  background-image: url(https://ghost.sk/chrome-error/purple.png);
  height: 40px;
  width: 40px;
}

table.solid td {
  background-color: purple;
  height: 40px;
  width: 40px;
}

div.image {
  background-image: url(https://ghost.sk/chrome-error/purple.png);
  height: 40px;
  width: 40px;
  display: inline-block;
}
Table with image bg (glitch both desktop and mobile):

<table class="image">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

Table with solid bg (glitch usually only mobile):

<table class="image">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

On mobile it glitches for divs too (more likely with images than solid colors):

<div>
  <div class="image">a</div><div class="image">b</div>
</div>
<div>
  <div class="image">c</div><div class="image">d</div>
</div>

Notes:

  • In demo I use 0.5px initial padding but in real code I am not intentionally setting it to fractions, it can happen any time, e.g. when centering table or when using padding-left 1em and then it depends on font.

  • In demo I'm using image filled with solid color to show it better (if it was solid color I wouldn't use image and besides on mobile it shows same glitch when using solid colors too).

  • It "feels" like OpenGL's error when "clamp to edge" is not set.

  • I'm not using tables in my original design, it's just is easier to trigger it with tables.

  • Here is screenshot how it look like: https://ghost.sk/chrome-error/screenshot.png

  • Tested on: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/69.0.3497.81 Chrome/69.0.3497.81 Safari/537.36

3 Answers

I had the same problem, look at this Youtube video : https://youtu.be/y88k6khLGvs. On my case, the thin gray lines where appearing only when the scroll bar was showing on the body.

But, found a solution that worked for me. Since Chrome seems to take 1 px at the end of each background-image, I changed my background CSS from this :

td
{
    background-repeat: repeat-x;
}

to

td
{
    background-size: 110% 100%;
    background-repeat: no-repeat;
}

It simply tells Chrome to go beyond the last pixel of the TD and renders it correctly.

This problem is indicated here. Chrome cause the background-image to restart in each cell, rather than flowing nicely uninterrupted for the whole row. I hope this will be fixed in the next versions of chrome.

I was stuck with this bug for some while and finally find a simple solution. Just add background-repeat: no-repeat on td. background-repeat: no-repeat on tr if the background is on tr

Related