Introduction to using svg in CSS background images (with examples)

不言
Release: 2018-10-27 16:32:47
forward
17135 people have browsed it

This article brings you an introduction to the use of svg in CSS background images (with examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

When using SVG in CSS background images, you can use many features of the css background attribute, such as image size and image position, etc. It is very easy to control the size of the image according to the size of the device. Another advantage is that you do not need to insert SVG images into the html, thus keeping the html clean.

Using SVG in CSS background images has many advantages and is also very helpful in improving performance. So when using SVG in a CSS background image, is there any way to change its color? Read on.

CSS mask

Use mask in CSS to change the background color. This method is simple and practical. The important thing is that browsers now support it more and more. good. The mask attribute can be used to create a mask based on the outline of the element. Using the mask can only display the area of the specified image content, while the area outside the image area is hidden. The following is how to use it:

.icon { background-color: red; -webkit-mask-image: url(icon.svg); mask-image: url(icon.svg); }
Copy after login

mask also has many attributes, such as mask-position, mask-repeat and mask-size, which are similar to the corresponding attributes of background images in CSS, and You can use abbreviated syntax like background:

.icon { background-color: red; -webkit-mask: url(icon.svg) no-repeat 50% 50%; mask: url(icon.svg) no-repeat 50% 50%; }
Copy after login

Browser support for masks is getting better and better. You can check the support of various browsers through the following address:

https://caniuse.com/#search=mask-image

In addition, if it is not limited to If you modify it in css, you can directly modify the svg source file

Drag the svg image into the editor to see the svg source code

      
Copy after login

Directly find thefill insideJust modify the color value in the attribute

The above is the detailed content of Introduction to using svg in CSS background images (with examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
svg
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!