htmlHow to set the transparency of div: 1. Using the opacity attribute, you only need to add the "opacity: transparency value;" style to the div element; 2. Using the filter attribute, you only need to add "filter" to the div element. :opacity (transparency value);" style.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
htmlSet the transparency of div
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> .box1{ width: 300px; height: 200px; background-color: yellow; } .box2{ width: 100px; height: 100px; background-color: green; } </style> </head> <body> <div class="box1"> <div class="box2"></div> </div> </body> </html>
1. Use the opacity attribute to set the transparency The smaller the value, the more transparent it is.
.box2{ width: 100px; height: 100px; background-color: green; opacity: 0.8; }
.box2{ width: 100px; height: 100px; background-color: green; opacity: 0.5; }
.box2{ width: 100px; height: 100px; background-color: green; opacity: 0.2; }
2. Use filter: opacity (transparency value);
, the smaller the transparency value, the more transparent it is.
.box2{ width: 100px; height: 100px; background-color: green; filter:opacity(0.5); }
.box2{ width: 100px; height: 100px; background-color: green; filter:opacity(0.1); }
Recommended tutorial: "html video tutorial"
The above is the detailed content of How to set the transparency of div in html. For more information, please follow other related articles on the PHP Chinese website!