0

html {
  background:#ffffff;
}
body {
  height:250px;
  background: linear-gradient(
    to bottom,
    #ffffff 0px,
    #ffffff 100px,
    #0065A2 100px,
    #0065A2 145px,
    #074A8B 145px,
    #074A8B 163px,
    #0065A2 163px,
    #0065A2 203px,
    transparent 203px
  );
}

I am trying to use a background linear gradient and with great surprise it works good on Firefox and IE but not on Google Chrome.

The code is here for example: https://jsfiddle.net/be1rgpez/1/

background: linear-gradient(
    to bottom,
    #ffffff 0px,
    #ffffff 100px,
    #0065A2 100px,
    #0065A2 145px,
    #074A8B 145px,
    #074A8B 163px,
    #0065A2 163px,
    #0065A2 203px,
    transparent 203px
);

I need a linear gradient with several color stops, but using Google Chrome it renders a strange shadow between colors (see image left box). The effect I need is "striped" without shadows).

In the attachment I show what I see using Chrome. The left box is what I need but without the shadows (like in the right box). The same jsfiddle renders correctly on Firefox and IE.

enter image description here

UPDATE: this is a zoomed picture. As you can see, the left box has a small shadow between the white and the blue color (and also between other colors).

enter image description here

2
  • 1
    I don't know much about gradients, but it works if you use % instead of px's. Commented May 12, 2017 at 8:32
  • @Pete in the image attached the left box show a small shadow between colors. I need the effect on the right box, without shadow between colors (white and blue). But I need it with more colors (white, blue, dark blue...). Google chrome seems to render that small shadow when using more than 2 colors (or 2 stripes).
    – webpaul
    Commented May 12, 2017 at 8:36

3 Answers 3

1

try this code:

.left {
    background: linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
    background: -webkit-linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
}

.right {
    background: linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
    background: -webkit-linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
}
1
  • this code only have 1 color change (from #ffffff to #0065A2) and it works on chrome. But I need more color changes: #ffffff, #0065A2, #074A8B, then again #0065A2 and transparent at the end. Several colors seems to have a buggy behavious on chrome (like i wrote in the question).
    – webpaul
    Commented May 12, 2017 at 8:49
1

I found that there's an issue between linear gradient and containers overflow. I tried many solutions and it didn't work.

Then when i tried to give overflow:auto, it worked for me.

this is before i apply the fix to the right container which holds many content

this is after applying the overflow: auto !important; to the right container and it works fine now without any issue and here it is.

0

You have defined the same starting points two times for different colors. The below code without the duplicates looks fine:

.left {
     background: linear-gradient(
        to bottom,
        #ffffff 0px,
        #0065A2 100px,
        #074A8B 145px,
        #0065A2 163px,
        transparent 203px
    );
}
2
  • This code generates gradients. I need stripes with net color changes. No gradient needed. This is why I am using the same pixel "stops": so I can chagne the color without the smooth/gradient effect.
    – webpaul
    Commented May 12, 2017 at 8:43
  • 1
    graphicdesign.stackexchange.com/questions/8426/…
    – Gerard
    Commented May 12, 2017 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.