Home > Web Front-end > CSS Tutorial > How to set the color of css background image

How to set the color of css background image

青灯夜游
Release: 2023-01-07 11:45:05
Original
12313 people have browsed it

In css, you can use the background and background-blend-mode attributes to set the background image color. The syntax format is "background: url (background image path), color value; background-blend-mode: lighten;".

How to set the color of css background image

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Using background-blend-mode

The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.icon1 {
width: 180px;
height: 180px;
background: url(img/1.jpg);
background-size: cover;
}
.icon2 {
width: 180px;
height: 180px;
background: url(img/1.jpg), linear-gradient(#f00, #c10);
/* background: url(img/1.jpg),red; */
background-blend-mode: lighten;
background-size: cover;
}
</style>
</head>
<body>
<div>原图:</div><br />
<div></div>
</body>
</html>
Copy after login

Rendering:

How to set the color of css background image

Description:

lighten This blending mode: lighten, lighten mode and darken mode have the opposite effect. Black is darker than any color, so black will be replaced by any color. On the other hand, if the background color of the material is black, the main color is white. Then you should use the darken blending mode.

linear-gradient(#f00, #00f )You can also achieve the effect of gradient color.

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set the color of css background image. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template