<!doctype html> <html> <head> <meta set="utf-8"> <title>CSS给背景图加透明度</title> <style> .bg { width: 500px; height: 300px; display: block; position: relative; } .bg::after { content: ""; background: url(https://www.jq22.com/img/cs/500x300-1.png); opacity: 0.3; top: 0; left: 0; bottom: 0; right: 0; position: absolute; z-index: -1; } </style> </head> <body> <div class="bg"></div> </body> </html>