css实现背景模糊案例

通过filter属性实现,具体如下

 

<!DOCTYPE HTML>
<html lang="en-US">
	<head>
		<meta charset="UTF-8">
		<title>高斯背景模糊效果(毛玻璃)</title>
		<style>
			.box {
				background: url('./img/timg.jpg') no-repeat 100% 100%;
				width: 750px;
				height: 400px;
				background-size: cover;
				position: relative;
			}

			.content {
				height: 60%;
				width: 60%;
				background: white;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -30%;
				margin-top: -16%;
				border-radius: 4px;
			}

			/* filter是对该元素的模糊,因此对content添加并模糊伪元素,并定位到content的下层,而不是直接修改背景图或content的样式 */
			.content::before {
				content: '';
				position: absolute;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
				filter: blur(3px);
				margin: -21px;
				background: url('./img/timg.jpg') no-repeat 100% 100%;
				background-size: cover;
				opacity: .8;
			}

			.content p {
				padding: 20px 15px;
				color: white;
				text-indent: 20px;
				font-size: 14px;
				line-height: 28px;
				letter-spacing: 1px;
				/* 清除子元素对父元素filter属性值的继承 */
				filter: blur(0);
			}
		</style>
	</head>
	<body>
		<div class="box">
			<div class="content">
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam eos adipisci perferendis quod
					repellendus commodi. Cum eveniet maxime quia quos voluptate officia itaque nesciunt voluptas ea
					adipisci. Fugiat voluptate enim.</p>
			</div>
		</div>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值