D
D
Denis Bukreev2016-10-28 14:50:09
css
Denis Bukreev, 2016-10-28 14:50:09

How to set gradient for SVG on hover?

There is an instagram icon - initially it is white.
But when you hover over it, a gradient with smooth animation should be applied.
I found in Google only how to initially put the gradient. And these are very cumbersome solutions, I expected that everything is simple with SVG.
SVGs are inserted via use

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yaroslav Ivanov, 2016-10-28
@space2pacman

https://jsfiddle.net/7zdoosp9/2/

A
Alexander Taratin, 2016-10-28
@Taraflex

One icon on top of another and change the transparency of the top one.

D
Denis Bukreev, 2016-10-28
@denisbookreev

In general, I created a gradient on the page:

<linearGradient id="instagrad" x1="0" y1="100%" x2="100%" y2="0">
            <stop class="stop stop--1"
                  stop-color="#febb26"
                  offset="0"></stop>
            <stop class="stop stop--2"
                  stop-color="#f74e0b"
                  offset="33%"></stop>
            <stop class="stop stop--2"
                  stop-color="#de003d"
                  offset="66%"></stop>
            <stop class="stop stop--3"
                  stop-color="#c0019e"
                  offset="100%"></stop>
        </linearGradient>

For svg on hover I applied:
&:hover {
  svg {
    fill: url(#instagrad);
  }
}

The problem is that the color change animation does not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question