Background blur with CSS

前端 未结 7 2237
忘了有多久
忘了有多久 2020-11-27 13:34

I want an Vista/7-aero-glass-style effect on a popup on my site, and it needs to be dynamic. I\'m fine with this not being a cross-browser effect as long as

7条回答
  •  萌比男神i
    2020-11-27 14:05

    Use an empty element sized for the content as the background, and position the content over the blurred element.

    #dialog_base{
      background:white;
      background:rgba(255,255,255,0.8);
    
      position: absolute;
      top: 40%;
      left: 50%;
      z-index: 50;
      margin-left: -200px;
      height: 200px;
      width: 400px;
    
      filter:blur(4px);
      -o-filter:blur(4px);
      -ms-filter:blur(4px);
      -moz-filter:blur(4px);
      -webkit-filter:blur(4px);
    }
    
    #dialog_content{
      background: transparent;
      position: absolute;
      top: 40%;
      left: 50%;
      margin-left -200px;
      overflow: hidden;
      z-index: 51;
    }
    

    The background element can be inside of the content element, but not the other way around.

    Some Content

    This is not easy if the content is not always consistently sized, but it works.

提交回复
热议问题