首页 > 开发 > CSS > 正文

CSS3打造磨砂玻璃背景效果

2024-07-11 08:32:28
字体:
来源:转载
供稿:网友

简介

这个效果是在看CSS Secrets这书上看到的,感觉很不错;

实现原理也挺简单的;

效果图及实现

效果图

代码实现

CSS Code复制内容到剪贴板
  1. <!DOCTYPE html>    <html lang="en">   
  2.     <head>            <meta charset="UTF-8">   
  3.         <title>Document</title>            <style>   
  4.                     /**                        * 设置背景图全屏覆盖及固定  
  5.                      * 设置内部元素偏移                        */  
  6.                     body {                            /*此处背景图自行替换*/  
  7.                         background: url(demo.jpg) no-repeat center center fixed;                            background-size: cover;   
  8.                          min-height: 100vh;                            box-sizing: border-box;   
  9.                         margin: 0;                            padding-top: calc(50vh - 6em);   
  10.                         font: 150%/1.6 Baskerville, Palatino, serif;                        }   
  11.                        /**  
  12.                      * 整体居中功能;                        * 背景透明虚化  
  13.                      * 溢出隐藏                        * 边缘圆角化  
  14.                      * 文字增加淡阴影                        */  
  15.                     .description{                            position: relative;   
  16.                         margin: 0 auto;                            padding: 1em;   
  17.                         max-width: 23em;                            background: hsla(0,0%,100%,.25) border-box;   
  18.                         overflow: hidden;                            border-radius: .3em;   
  19.                         box-shadow: 0 0 0 1px hsla(0,0%,100%,.3) inset,                                        0 .5em 1em rgba(0, 0, 0, 0.6);   
  20.                         text-shadow: 0 1px 1px hsla(0,0%,100%,.3);                        }   
  21.                        /*使用滤镜模糊边缘*/  
  22.                     .description::before{                            content: '';   
  23.                         position: absolute;                            top: 0; rightright: 0; bottombottom: 0; left: 0;   
  24.                         margin: -30px;                            z-index: -1;   
  25.                         -webkit-filter: blur(20px);                            filter: blur(20px);   
  26.                     }            </style>   
  27.     </head>        <body>   
  28.         <p class="description">            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod   
  29.         tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo   
  30.         consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse            cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non   
  31.         proident, sunt in culpa qui officia deserunt mollit anim id est laborum.            </p>   
  32.     </body>    </html>   
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表