<style>
        *{
            padding: 0px;
         margin: 0px;
        }
      
.container { width: 100%;height: 900px;
position: relative; /*确保伪元素能正确定位*/}
.container::before {
content: "";/*伪元素需要内容,即使它是空的*/
position:absolute;
top: 0;
right: 0;bottom: 0;left: 0;
background: url(n1.jpg) no-repeat;background-size: cover;/*或其他你需要的背景大小*/
opacity : 0.2;/*设置透明度*/
z-index : -1;/*确保伪元素在内容之下*/}
       
    </style>
</head>
<body>
    
        测试背景半透明
    
    
</body>