利用伪类实现背景高斯模糊,消除父元素对子元素的影响
<!DOCTYPE html>
<html>
<head>
<title>高斯模糊</title>
<style type="text/css">
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#app {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
#app::before {
content: "";
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(255, 167, 30, 0.4);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
z-index: -1;
/* 重要 */
left: 0;
right: 0;
bottom: 0;
top: 0;
}
#app img {
width: 80%;
}
</style>
</head>
<body>
<div id="app">
<img src="https://tse4.mm.bing.net/th?id=OIP.MglsPcsUSOR9MRzvZrthUAHaEo&pid=Api&w=1920&h=1200&rs=1&p=0">
</div>
</body>
</html>