Home >Web Front-end >CSS Tutorial >How to set the background image to be transparent in css
In CSS, you can use the opacity attribute to set the background image to be transparent. The function of this attribute is to set the transparency of the element. You only need to add the "opacity: transparency value;" style to the element with the background image set. .
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
In CSS, you can use the opacity attribute to set the background image to be transparent.
The Opacity attribute sets the transparency level of an element. The transparency level (property value) ranges from 0.0 (fully transparent) to 1.0 (fully opaque).
Code example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> div{ width: 400px; height: 230px; background:url(img/3.jpg) no-repeat; background-size: 400px 226px; } .box{ opacity: 0.5; } </style> </head> <body> <div></div> <div class="box"></div> </body> </html>
Effect picture:
(Learning video sharing: css video Tutorial)
The above is the detailed content of How to set the background image to be transparent in css. For more information, please follow other related articles on the PHP Chinese website!