div
tag with background: green;
and it looks like this:face.svg
file:mask-image: url (face.svg);
property mask-image: url (face.svg);
to the div
tag, you will be amazed to see the result:div
, but assumed the background color. This is contrary to our expectations. This happens because of the mask-type
property, which makes the opaque part of svg transparent. This makes the background color visible.background-color
to change the color of the mask. If you are familiar with the different ways of using background-color
, you can also apply gradients and write a simple gradient that fills the center with red and radially spreads black around the edges. The code will look like this: background-image: -webkit-radial-gradient( hsla(0, 100%, 50%, .7), hsla(0, 100%, 20%, .8), hsla(0, 100%, 10%, 1));
expression.svg
, which you see in the image below. For simplicity, I created all the svg files of the same width and height, so I don’t have to align the faces and expressions manually.mask-image
has a cool option that allows you to use multiple images as masks. Therefore, we can do this: mask-image: url (face.svg), url (expression.svg);
. Here's what happened:mask-position
, thanks to which the mask is located in the upper left corner relative to the parent element. And I can arrange several masks using the mask-position
property in the same way as mask-image
. To make a face sad, use something like this: mask-position: 0 0, 0 12px;
. That's what happened.0 0
for face.svg
, and the second 0 12px
- for expression.svg
. This led to a transfer of 12px and gave the face the necessary expression. i { background-image: -webkit-radial-gradient(hsla(0, 100%, 50%, .7), hsla(0, 100%, 20%, .8) 60%, hsla(0, 100%, 10%, 1)); mask-image: url('face.svg'), url('expression.svg'); mask-position: 0 0, 0 12px; /* To make the sad expression */ transition: mask-position .5s ease-out; } i:hover { background-image: -webkit-radial-gradient(hsla(120, 100%, 50%, .7), hsla(120, 100%, 20%, .8) 60%, hsla(120, 100%, 10%, 1)); mask-position: 0 0, 0 0; /* To make the happy expression */ transition: mask-position .1s linear; }
-webkit-
, -moz-
and -0-
.
Go to VPS.today - a site for searching virtual servers. 1500 tariffs from 130 hosters, convenient interface and a large number of criteria for finding the best virtual server.
Source: https://habr.com/ru/post/428666/
All Articles