CSS3 Box Shadow on Top, Left, and Right Only

前端 未结 10 1749
终归单人心
终归单人心 2020-12-15 03:24

Greetings,

I am trying to apply a CSS3 box shadow to only the top, right, and left of a DIV with a radius that matches the result of the following CSS (minus the bot

10条回答
  •  心在旅途
    2020-12-15 03:47

    I know this is very old, but none of these answers helped me, so I'm adding my answer. This, like @yichengliu's answer, uses the Pseudo ::after element.

    #div {
        position: relative;
    }
    
    
    
    #div::after {
        content: '';
        position: absolute;
        right: 0;
        width: 1px;
        height: 100%;
        z-index: -1;
    
        -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,1);
        -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,1);
        box-shadow: 0px 0px 5px 0px rgba(0,0,0,1);
    }
    
    /*or*/
    
    .filter.right::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        width: 1px;
        height: 100%;
        background: white;
        z-index: -1;
    
        -webkit-filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 1));
        filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 1));
    }
    

    Fiddle

    If you decide to change the X of the drop shadow (first pixel measurement of the drop-shadow or box-shadow), changing the width will help so it doesn't look like there is a white gap between the div and the shadow.

    If you decide to change the Y of the drop shadow (second pixel measurement of the drop-shadow or box-shadow), changing the height will help for the same reason as above.

提交回复
热议问题