V
V
Vetelek2018-05-20 11:01:58
css
Vetelek, 2018-05-20 11:01:58

How to do fallback for svg in css styles?

Good morning friends. I have a problem, I don’t know how to properly make a fallback for svg using png, namely, I want to do it in the ::before pseudo-element, background doesn’t work there where you can list icons separated by commas. The result should be something like this:
5b012b579173e633693946.png
Maybe there are some other ways to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2018-05-20
@SergeiB

You can write like this:

.selector::before {
  content: "";
  background: url(fallback.png);
  background: url(background.svg);
}

If the browser does not support svg, it will simply not apply the second rule. You can also install the modernizr
library , which will check if the browser supports svg. If not, this plugin will give the html tag a no-svg class that we can rely on:
.selector::before {
  content: "";
  background: url("background.svg");
}
.no-svg .selector::before {
  content: "";
  background: url("background.png");
}

Here is a great article on svg fallbacks.

A
A person from Kazakhstan, 2018-05-20
@LenovoId

I don’t know what fullback is, but what you want is done through use
and then you can style it in css, but svg doesn’t know background because there is fill
information on fill
information on use

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question