Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css clip-path little gap between

The code is below. gradient there is a very small gap between two divs.but it should not have.

.gra {
  position: absolute;
  width: 200px;
  height: 200px;
}

.left {
  background: linear-gradient(0deg, red 0%, blue 100%);
  clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
}

.right {
  background: linear-gradient(270deg, red 0%, blue 100%);
  clip-path: polygon(0% 0%, 100% 0%, 100% 100%);
}
<div class='gra left'></div>
<div class='gra right'></div>
like image 936
David Xu Avatar asked Jun 19 '26 05:06

David Xu


2 Answers

It's happening because of Antialiasing.

Use left:0; with the left class and left: -1px; with the right class to overlap Antialiasing

.gra {
  position: absolute;
  width: 200px;
  height: 200px;
}

.left {
  background: linear-gradient(0deg, red 0%, blue 100%);
  clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
  left:0;
}

.right {
  background: linear-gradient(270deg, red 0%, blue 100%);
  clip-path: polygon(0% 0%, 100% 0%, 100% 100%);
  left: -1px;
}
<div class='gra left'></div>
<div class='gra right'></div>
like image 149
Abhishek Pandey Avatar answered Jun 22 '26 00:06

Abhishek Pandey


You can change by:

clip-path: polygon(-1% 0%, 100% 0%, 100% 101%);

.gra {
  position: absolute;
  width: 200px;
  height: 200px;
}

.left {
  background: linear-gradient(0deg, red 0%, blue 100%) ;
  clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
}

.right {
  background: linear-gradient(270deg, red 0%, blue 101%);
  clip-path: polygon(-1% 0%, 100% 0%, 100% 101%);
}
<div class='gra left'></div>
<div class='gra right'></div>
like image 28
Nicolás Alarcón Rapela Avatar answered Jun 21 '26 22:06

Nicolás Alarcón Rapela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!