Reputation: 987
I have an element with gradient as background color,
.foo{
background-image: repeating-linear-gradient(-45deg, #7cd4cf, #7cd4cf 1.5px, #49c8c1 2px, #49c8c1 4px);
width:250px;
height:250px;
}
<div class="foo">
</div>
I need to add an overlay of gradient on the top of it - so it will looks like this :
As you can see - it's got gradient from left to right - on the top of the stripes.
I've tried add it by using :after - and it's working - but i already have pseudo element for this element - so it's override it. Is it possible to add more then one :after element? or perhaps their is a better way achieving that effect with only Css ? (no js please).
Thanks
Upvotes: 3
Views: 6099
Reputation: 66228
That's possible, if and only if the overlay is going to be a solid color. You simply overlay an additional horizontal gradient over the underlying repeating linear gradient, with #7cd4cf
fading out to opacity of 0.
#7cd4cf
at opacity 1 from left, ending with opacity 0 on the rightWith that logic in mind, the top layer can be coded like this: linear-gradient(90deg, rgba(124,212,207, 1), rgba(124,212,207,0))
. Note that the corresponding rgb colors of #7cd4cf
is rgb(124,212,207)
.
Note that background-images stack from bottom to top, i.e. the last specified background image will be at the bottom of the stack.
.foo {
background-image:
linear-gradient(90deg, rgba(124, 212, 207, 1), rgba(124, 212, 207, 0)),
repeating-linear-gradient(-45deg, #7cd4cf, #7cd4cf 1.5px, #49c8c1 2px, #49c8c1 4px);
width: 250px;
height: 250px;
}
<div class="foo">
</div>
Upvotes: 6
Reputation: 3878
2 gradients with transparency:
.foo{
background-image: repeating-linear-gradient(-45deg, #7cd4cf, #7cd4cf 1.5px, rgba(73, 200, 193, 0.3) 2px, rgba(73, 200, 193, 0.3) 4px), linear-gradient(45deg, #7cd4cf, rgba(73, 200, 193, 0.3));
width:250px;
height:250px;
}
<div class="foo">
</div>
Upvotes: 1