The gradient div acts as a background. The SVG image (logo div) should overlay the gradient div with a full-width-and-height white background, showing the gradient colors through the transparent parts of the logo.
You could do this a number of ways.
Have a plan white background, the the logo element can have both the gradient and image applied as the background.
Or have the image as an <img> with a gradient background.
Or have the gradient be within the image and the white parts be transparent.
Yes, that was the intention. I wanted the gradient to be 100% width and height.
And then on top of it another div with white background as 100% width and height, with the SVG centred in the middle, so that it shows the gradient through its transparent parts. But when I make this div’s bg as white, it shows white through the transparent parts.
Will have to think of a different way of structuring it. Going to try some of the suggestions below.
The way to do it would be to have an svg with gradient fill on a white background.
As it is, the svg has a viewbox bigger than the white rectangle, so it won’t block the background out even if it fills the container 100%.
I like the idea of having a completely white background and having logo div to have both the gradient and image applied as the background. How would you do this?
The problem is that the animated gradient is called up when I use gradient.
body
{
padding: 0px;
margin: 0px;
background-color:#FFFFFF;
}
#gradient << calls up animated gradient
{
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
position:absolute;
z-index: -99999;
}
#logo {
width:100%;
height:100%;
background:url(cubic-logo-ws.svg) center center no-repeat; << How to apply animated gradient here?
}
Here is a crude example using css animation that could probably be improved upon, I have not worked with gradients in svg before, or done much with css animation, so putting the two together didn’t go as well as it could have.
I’m not sure you can apply a css gradient directly to the fill property in css, it did not work putting them in the keyframes anyway. I think you have to apply the gradient via the <defs> as per the article and I wasn’t sure how to animate that.
So I cheated and applied an animated hue rotate filter to the svg. It sort of works, but the hue rotate does not account for the differing brightness of the colours, so some get a bit muddy.
The second example is a flat colour, not gradient with animated hsl colours.
Unfortunately, although the colours are defined in HSL, they are still interpolated internally by animation (and gradients for that matter) in RGB. So I could not just have 2 keyframes, 0deg @ 0% and 360deg @ 100%. It needs a few tween frames to give a smooth hue rotation. Probably more than the 90deg increment ones I added.
I do wish css would interpolate colours in the mode you use if they are all the same, not in RGB all the time.