How can I add a box-shadow on one side of an element?

后端 未结 13 1080
萌比男神i
萌比男神i 2020-11-28 17:34

I need to create a box-shadow on some block element, but only (for example) on its right side. The way I do it is to wrap the inner element with box-shado

13条回答
  •  北海茫月
    2020-11-28 18:06

    To get the clipped effect on up to two sides you can use pseudo elements with background gradients.

    header::before, main::before, footer::before, header::after, main::after, footer::after {
        display:    block;
        content:    '';
        position:   absolute;
        width:      8px;
        height:     100%;
        top:        0px;
    }
    
    header::before, main::before, footer::before {
        left:       -8px;
        background: linear-gradient(to left, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
    }
    
    header::after, main::after, footer::after {
        right:      -8px;
        background: linear-gradient(to right, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
    }
    

    will add a nice shadow-like effect to the left and right of the elements that normally make up a document.

提交回复
热议问题