CSS3 Box Shadow on Top, Left, and Right Only

前端 未结 10 1555
终归单人心
终归单人心 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:38

    You can give multiple values to box-shadow property
    eg

    -moz-box-shadow: 0px 10px 12px 0px #000,
                        0px -10px 12px 0px #000;
    -webkit-box-shadow: 0px 10px 12px 0px #000,
                        0px -10px 12px 0px #000;
    box-shadow: 0px 10px 12px 0px #000,
                0px -10px 12px 0px #000;
    

    it is drop shadow to left and right only, you can adapt it to your requirements

    0 讨论(0)
  • 2020-12-15 03:39

    It's better if you just cover the bottom part with another div and you will get consistent drop shadow across the board.

    #servicesContainer {
      /*your css*/
      position: relative;
    }
    

    and it's fixed! like magic!

    0 讨论(0)
  • 2020-12-15 03:40

    Adding a separate answer because it is radically different.

    You could use rgba and set the alpha channel low (to get transparency) to make your drop shadow less noticeable.

    Try something like this (play with the .5)

    -webkit-box-shadow: 0px -4px 7px rbga(230, 230, 230, .5);
    -moz-box-shadow: 0px -4px 7px rbga(230, 230, 230, .5);
    box-shadow: 0px -4px 7px rbga(230, 230, 230, .5);
    

    Hope this helps!

    0 讨论(0)
  • 2020-12-15 03:43

    I found a way to cover the shadow with ":after", here is my code:

    #div:after {
        content:"";
        position:absolute;
        width:5px;
        background:#fff;
        height:38px;
        top:1px;
        right:-5px;
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-15 03:52

    The following code did it for me to make a shadow inset of the right side:

    -moz-box-shadow: inset -10px 0px 10px -10px #000;
    -webkit-box-shadow: inset -10px 0px 10px -10px #000;
    box-shadow: inset -10px 0px 10px -10px #000;
    

    Hope it will help!!!!

    0 讨论(0)
提交回复
热议问题