Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Crisp boundaries for linear gradient

Tags:

html

css

I am using linear gradient to generate two sections of a div with a trapezium-like border. I am not able to get a crisp boundary between the two colors, I get a very narrow region of gradient - I have been able to reduce it, but I haven't been able to reduce it completely.

This is the code I have 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>
like image 865
Rimil Dey Avatar asked Mar 01 '26 05:03

Rimil Dey


1 Answers

Your declaration of the gradient produces a step of 1% between #ffffffand #197f88. Change this 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 crisp boundaries (but the angle is rather 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>

On A Collection of Separator Styles there you can see many different and sharp separator styles. May it's helpful for your approach.

like image 177
RWAM Avatar answered Mar 02 '26 17:03

RWAM