Box-shadow only on right and left

前端 未结 4 2005
失恋的感觉
失恋的感觉 2021-01-05 06:24

I need to make a box-shadow only on the right and left of an element. It should fade and get thinner to the top and bottom. It also shouldn\'t oveflow on top and bottom.

4条回答
  •  隐瞒了意图╮
    2021-01-05 06:42

    You will need to use two box-shadows one for the left shadow and one for the right one. You need to specify both box-shadows in the same box-shadow attribute and seperate them with a coma :

    box-shadow: -60px 0px 100px -90px #000000, 60px 0px 100px -90px #000000;
    

    Both need to have a negative spread value so they are shorter than the divs height and don't overflow on the top and bottom.

    DEMO

    output :

    box-shadow only on the left and right

    You will need to tweak the values of the shadow in order to adapt it to the size of the element you want to use it on.

    HTML :

    CSS :

    div{
        height:500px;
        width:300px;
        margin:0 auto;
        box-shadow: -60px 0px 100px -90px #000000, 60px 0px 100px -90px #000000;
    }
    

提交回复
热议问题