web开发笔记一毛玻璃效果

简介

今天介绍一个小技巧,如何用css制作出毛玻璃效果

内容

先看效果图:

blur.png

然我来说下制作思路, 首先我要说下blur的影响范围,它会使其本身以及其子元素的内容变模糊. 因此错误的做法会使得模糊背景上的文字也变模糊,如图:

eg2.png

解决办法发就是把图片和文字两者分离出来.这里采用伪元素的做法,把模糊背景图分离出来.代码如下:

 .blur::after {
            content: '';
            height: 100%;
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            background-attachment: fixed;
            background-size: cover;
            background-image: url(./../image/bg1.jpg);
            filter: blur(20px);
            z-index: -1;
        }

其中这里需要注意的是 background-attachment: fixed ; background-size: cover;(缺一不可),正是靠这两个属性才使得背景模糊图和背景图比较完美衔接在一起,若不设置的话效果如下:

eg3.png

值得注意的地方就这两点,下面我把代码列出来.

-css : 
 body {
            background-repeat: no-repeat;
            background-size: cover;
            background-attachment: fixed;
            background-image: url(./../image/bg1.jpg);
            font-size: 19px;
            font-family: 'Verdana', 'Arial';
        }
        
        .blur {
            width: 650px;
            position: relative;
            box-shadow: 1px 1px 3px black;
            border-radius: 20px;
            padding: 50px;
            margin: 120px auto;
            overflow: hidden;
        }
        .blur::after {
            content: ' ';
            height: 100%;
            width: 100%;
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            background-attachment: fixed;
            background-size: cover;
            background-image: url(./../image/bg1.jpg);
            filter: blur(15px);
            z-index: -1;
        }

-html :
<div class="blur">
        <h1>WARFRAME</h1>
        <p>The Grineer, with their endless clone armies, have plunged the system into chaos. There is only one force that can match them, you. You are Tenno, an ancient warrior, a master of gun and blade. You wield the mighty Warframes and command their
            awesome powers. Forge your weapons. Gather like-minded Tenno and take the fight back to the Grineer. The Origin System needs you once again. Are you ready?</p>
    </div>

结束

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 6,857评论 0 11
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 5,864评论 0 2
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,856评论 25 709
  • (1). 阴影模糊半径与阴影扩展半径的区别:阴影模糊半径:此参数可选,其值只能是为正值,如果其值为0时,表示阴影不...
    Leisure_blogs阅读 5,418评论 0 6
  • 目前学琴已有2年。在这之前,我万万没想到会和钢琴结缘。 我很惭愧,在过去的三十多年里,我并未为自己培养出太多的兴趣...
    艾寇阅读 4,705评论 2 50