CSS實現毛玻璃效果


HTML

<!-- 背景容器層 -->
<
div class="container"></div>
<!-- 遮罩層 --> <div class="mask"></div>

CSS

           body{
			padding: 0;
			margin: 0;
		}
		.container,
		.mask{
			height: 400px;
			width: 100%;
			position: absolute;
			top: 0;
		}
		.container{
			/* background: url(bg.png) no-repeat top/cover; */
			background-image: url(bg.png);
			background-repeat: no-repeat;
			background-position: top;
			background-size: cover;
			/* 高斯模糊 */
			filter: blur(10px); /* 容器四周出現灰色模糊帶 */
			z-index: -1;
		}
		.mask{
			background: #333; /* 黑色背景 */
			z-index: -2;  /* 使遮罩層位於背景容器層下方,背景容器模糊帶消失 */
		}

測試

/* 給遮罩層加個top,使其和容器背景分開 */
.mask{
    top: 180px;
}

效果

 

最終效果

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM