代码之家  ›  专栏  ›  技术社区  ›  Codemonkey

如何使用CSS创建运动模糊效果?

css
  •  4
  • Codemonkey  · 技术社区  · 9 年前

    通过应用多个方框阴影,我可以很好地处理具有纯色背景的对象:

    jsFiddle

    html:

    <div></div>
    

    css:

    div{width: 50px;
        height: 50px;
        margin: 100px;
        border-radius: 25px;
        background: rgb(0,150,0);
        box-shadow: -15px 0 12px rgba(0,150,0,0.2)
                  , -11px 0 10px rgba(0,150,0,0.4)
                  ,  -8px 0  8px rgba(0,150,0,0.6)
                  ,  -6px 0  6px rgba(0,150,0,0.8)}
    

    这并不理想,因为你会让阴影从元素上下流动,而不仅仅是向左侧流动,但它确实起到了作用。

    但我真正想要的是它能很好地与背景图像配合,例如 this jsFiddle 我想要边缘的颜色 div (或至少背景图像的边缘)进行拉伸。

    我该怎么做? 可以 我

    非常感谢。

    1 回复  |  直到 9 年前
        1
  •  4
  •   Kushtrim    9 年前

    你可以添加一个 ::before 然后复制元素并使其模糊。

    div{
      position: relative;
      width: 50px;
            height: 50px;
            margin: 100px;
            border-radius: 25px;
            background: url(https://i.imgur.com/pDj7wo9.png);
            background-size: cover;
            background-position: left center;
    }
    
    div::before {
        background: url(https://i.imgur.com/pDj7wo9.png);
        background-size: cover;
        background-position: left center;
        position: absolute;
        width: 55px;
        height: 55px;
        overflow: hidden;
        z-index: -1;
        filter: blur(5px);
        content: "";
        border-radius: 100%;
    }
    <div></div>