css实现毛玻璃效果

css实现毛玻璃效果

实现效果如图所示:
在这里插入图片描述
通过三层重叠实现:(通过z-index设置顺序)

最外层是文字显示的content层

中间层是背景层

最底层为模糊的content:before层

中间和最底层顺序可以互换。

源代码如下:

<html>

	<head>

		<meta charset="UTF-8">

		<title></title>

	    <style>

	    	.bg{

	    		background: url(img/pic1.jpg);

	    		margin: auto;

	    		position: relative;

	    		width: 600px;

	    		height: 500px;

	    		z-index: 0;

	    		}

	    	

	    	.content{

	    		width: 300px;

	    		height:300px;

	    		z-index: 1;

	    		border-radius: 5px;

	    		box-shadow: 0 10px 20px rgba(0,0,0,0.3);

	    		position: absolute;

	    		top: 25%;

	    		left: 25%;

	    		overflow: hidden;/*突出边缘*/

	    		background-size: cover;

	    	}

	    	.content:before{

	    		content: '';

	    		position: absolute;

	    		top: 0;

	    		left:0;

	    		z-index: -2;

	    		-webkit-filter: blur(15px);

	    		background-image:url(img/pic1.jpg);/*设置与大背景相同的背景图*/

	    		width: 300px;

	    		height: 300px;

	    		background-attachment: fixed;/*中间图与背景图拼接完全*/

	    		

	    	}

	    	h1{

	    		font-family: "微软雅黑";

	    		color: #fff;

	    		text-align: center;

	    		font-size: 50px;

	    	}

	    	p{

	    		font-family: "微软雅黑";

	    		color: #fff;

	    		text-align: center;

	    		font-size: 20px;

	    	}

	    </style>



	</head>

	<body>

		<div class="bg">

			<div class="content">

				<h1>CAT</h1>

				<p>a cat comimg from 360wallpaper,who seems quite lovely.

				</p>

			</div>

		</div>

			

	</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值