CSS blur and retain sharp edges using absolute div

前端 未结 3 2275
忘掉有多难
忘掉有多难 2021-02-19 05:58

This works just fine if img is not set to absolute:

div img {
    filter: blur(5px);
        -webkit-filter: blur(5px);
        -moz-filter: blur(5px);
        -         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 06:15

    put your blur element in a container like this:

    then instead of using height:100% and width:100% use like this:

    .container{
        position:relative;
        width:300px;          /* this is an example */
        height:300px;         /* this is an example */
        overflow:hidden;
    }
    
    #background {
        left:-15px;
        right:-15px;
        top:-15px;
        bottom:-15px;
        /* other styles */
    }
    

    you need to remove 15px (or more/less) from each side of your element.

    DEMO - Full DEMO

提交回复
热议问题