CSS - Clear Borders for Linear Gradients

I use a linear gradient to create two div sections with a trapezoidal border. I can’t get a clear border between the two colors, I get a very narrow gradient area - I was able to reduce it, but I was not able to completely reduce it.

This is the code I used:

.buyers-div {
  width: 100%;
  height: 500px;
  background: -moz-linear-gradient(337deg, #FFFFFF 50%, #FFFFFF 49%, #197f88 50%, #197f88 100%);
  /* ff3.6+ */
  background: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #FFFFFF), color-stop(49%, #FFFFFF), color-stop(50%, #197f88), color-stop(100%, #197f88));
  /* safari4+,chrome */
  background: -webkit-linear-gradient(337deg, #FFFFFF 50%, #FFFFFF 49%, #197f88 50%, #197f88 100%);
  /* safari5.1+,chrome10+ */
  background: -o-linear-gradient(337deg, #FFFFFF 50%, #FFFFFF 49%, #197f88 50%, #197f88 100%);
  /* opera 11.10+ */
  background: -ms-linear-gradient(337deg, #FFFFFF 50%, #FFFFFF 49%, #197f88 50%, #197f88 100%);
  /* ie10+ */
  background: linear-gradient(113deg, #FFFFFF 50%, #FFFFFF 49%, #197f88 50%, #197f88 100%);
  /* w3c */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FFFFFF', endColorstr='#197f88', GradientType=1);
  /* ie6-9 */
}
<div class="buyers-div"></div>
Run codeHide result
+4
source share
2 answers

Your gradient declaration creates a 1% step between #ffffffand #197f88. Change it from

background: linear-gradient(113deg, #FFFFFF 50%, #FFFFFF 49%, #197f88 50%, #197f88 100%);

to

background: linear-gradient(113deg, #FFFFFF 0%, #FFFFFF 50%, #197f88 50%, #197f88 100%);

and you get clear boundaries (but the angle is pretty suboptimal):

.buyers-div {
  width: 100%;
  height: 500px;
  background: -moz-linear-gradient(337deg, #FFFFFF 0%, #FFFFFF 50%, #197f88 50%, #197f88 100%);
  /* ff3.6+ */
  background: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #FFFFFF), color-stop(50%, #FFFFFF), color-stop(50%, #197f88), color-stop(100%, #197f88));
  /* safari4+,chrome */
  background: -webkit-linear-gradient(337deg, #FFFFFF 0%, #FFFFFF 50%, #197f88 50%, #197f88 100%);
  /* safari5.1+,chrome10+ */
  background: -o-linear-gradient(337deg, #FFFFFF 0%, #FFFFFF 50%, #197f88 50%, #197f88 100%);
  /* opera 11.10+ */
  background: -ms-linear-gradient(337deg, #FFFFFF 0%, #FFFFFF 50%, #197f88 50%, #197f88 100%);
  /* ie10+ */
  background: linear-gradient(113deg, #FFFFFF 0%, #FFFFFF 50%, #197f88 50%, #197f88 100%);
  /* w3c */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FFFFFF', endColorstr='#197f88', GradientType=1);
  /* ie6-9 */
}
<div class="buyers-div"></div>
Run codeHide result

In the Separator Style Collection there you can see many different and sharp separator styles. Let it be useful for your approach.

+2

, relative/absolute Before pseudo-element. :

//HMTL(PUG)
.buyers-div

CSS(SASS)
.buyers-div
  position:relative
  width: 100%
  height: 500px
  background-color: #197f88
  overflow: hidden
  &:before
    content: ''
    position: absolute
    width: 100%
    height: 500px
    background-color: white
    left: -50%
    transform: skew(-45deg)

, T04435

0

Source: https://habr.com/ru/post/1677346/


All Articles