Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS linear opacity

Tags:

css

I want to create some flat-UI-like blocks but I need a little help. I got through some guides with linear-gradient(to left, rgba(255,255,255,0) ,rgba(255,255,255,1)); and so on, but I have't found what I actually need.

Is there any way, how to do any layer with linear opacity? I have quite huge database of images, (so I definitely can't photoshop them to have opacity by itself), and I am loading it into many "div" as a background-image. But I need to make the divs to start beeing transparent in about 75% of its width.

Is it somehow possible in CSS?

There is what I need to achieve:

enter image description here

like image 712
Zorak Avatar asked Oct 27 '25 12:10

Zorak


2 Answers

You can set a linear gradient background with an extra stop to make an element transparent for 75% of its width, then linearly increase opacity.

For example:

background: linear-gradient(
   to right, 
   rgba(0,0,0,1) 0%,
   rgba(0,0,0,1) 75%,
   rgba(0,0,0,0) 100%
);

This makes an element have an opaque black (the three first rbga values) background for 75% of its width, then linearly transition to transparent in its rightmost 25%.

like image 178
Jon Avatar answered Oct 30 '25 06:10

Jon


I'm afraid something like that is not possible using CSS. Since you have many images, and provided you don't show too many of them at once, you can consider using canvas to render the opacity to each image:

http://jsfiddle.net/u256zkha/

like image 45
Shomz Avatar answered Oct 30 '25 05:10

Shomz



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!