I have an element with content inside it.
The element - with its content - should be fully opaque on the left , fully transparent on the right. Evenly graded from right to left.
As the content and background it is merging into are not fixed, there is no way to make an image in advance.
I am aware that gradients can be used as backgrounds (-moz-linear-gradient), but that doesn't help me - here, I need the contents of the element themselves to fade out.
I have been able to do this in IE (Alpha Mask) and Webkit (image-mask), but have been completely stumped in FF.
I don't mind using SVG if there is a way there.
Please help?
Linear Gradient - Transparency To add transparency, we use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).
First, -webkit-gradient uses a two-point syntax that lets you explicitly state where a linear gradient starts and ends. linear-gradient does away with this in favor of convenient box-filling behavior. If you really want the gradient to stop before the edges of the box, you can do so via color stop placement.
The opacity CSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency.
This page explains how to achieve this for FF 3.5+
https://developer.mozilla.org/en/applying_svg_effects_to_html_content
You probably want something like this in a file called mask.svg:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
version="1.1"
baseProfile="full">
<mask id="m1" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
<linearGradient id="g" gradientUnits="objectBoundingBox" x2="1">
<stop stop-color="white" offset="0"/>
<stop stop-color="white" stop-opacity="0" offset="1"/>
</linearGradient>
<rect x="0" y="0" width="1" height="1" fill="url(#g)"/>
</mask>
</svg>
Then include the following in your CSS:
mask: url(/path/to/mask.svg#m1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With