Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the white edges that appear in between two skewed elements?

I see a white line between skewed HTML divs on Chrome browser. Below is a screenshot of the issue:

enter image description here

Here's the code :

.abc {
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility:    hidden;
  backface-visibility: hidden;
  width: 200px;
  height: 200px;
  background: green;
  position: absolute;
  left:0px;
  transform: skewX(-10deg);
  transform-origin: 0% 100%;
}

.def {
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility:    hidden;
  backface-visibility: hidden;
  width: 200px;
  height: 200px;
  background: green;
  position: absolute;
  left:200px;
  transform: skewX(-10deg);
  transform-origin: 0% 100%;

}

A debug sample is available at : https://jsbin.com/dijazit/2/edit?html,css,output

How do we remove this white line? Appreciate any help here.

like image 364
moondram Avatar asked Mar 29 '16 15:03

moondram


People also ask

How do you transform skew?

The skew() function is an inbuilt function which is used to transform an element in the 2D plane. Skew an element means to pick a point and push or pull it in different directions. Parameters: ax: This parameter holds the angle representing the horizontal axis to distort an element.

How do you use skew properties?

The skew() function is specified with either one or two values, which represent the amount of skewing to be applied in each direction. If you only specify one value it is used for the x-axis and there will be no skewing on the y-axis.

What parameters does skew accept?

The skew() function accepts two arguments, indicating the angle of the skew for the x and y axes respectively. These are represented by angle values. If only one value is supplied, the second value has a zero value.


1 Answers

This is kind of a known issue with respect to rendering transformed elements in Chrome. What makes it more weird is the fact that we come across many similar issues and each time the fix applied for the previous (very similar) case ends up not working for the current one.

For this particular scenario, adding a transparent 1 pixel border around the elements seems to fix it.

.abc {
  position: absolute;
  left: 0px;
  width: 200px;
  height: 200px;
  background: green;
  transform-origin: 0% 100%;
  transform: skewX(-10deg);
  border: 1px solid transparent;
}
.def {
  position: absolute;
  left: 200px;
  width: 200px;
  height: 200px;
  background: green;
  transform-origin: 0% 100%;
  transform: skewX(-10deg);
  border: 1px solid transparent;
}
<div class="abc"></div>
<div class="def"></div>
like image 83
Harry Avatar answered Nov 15 '22 00:11

Harry