How to apply box-shadow on all four sides?

后端 未结 10 1159
傲寒
傲寒 2020-12-13 05:47

I\'m trying to apply a box-shadow on all four sides. I could only get it on 2 sides:

\"\"

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 06:07

    CSS3 box-shadow: 4 sides symmetry

    1. each side with the same color

    :root{
      --color: #f0f;
    }
    
    div {
      display: flex;
      flex-flow: row nowrap;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      margin: 50px auto;
      width: 200px;
      height: 100px;
      background: #ccc;
    }
    
    .four-sides-with-same-color {
      box-shadow: 0px 0px 10px 5px var(--color);
    }

    1. each side with a different color

    :root{
      --color1: #00ff4e;
      --color2: #ff004e;
      --color3: #b716e6;
      --color4: #FF5722;
    }
    
    div {
      display: flex;
      flex-flow: row nowrap;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      margin: 50px auto;
      width: 200px;
      height: 100px;
      background-color: rgba(255,255,0,0.7);
    }
    
    .four-sides-with-different-color {
      box-shadow: 
        10px 0px 5px 0px var(--color1),
        0px 10px 5px 0px var(--color2),
        -10px 0px 5px 0px var(--color3),
        0px -10px 5px 0px var(--color4);
    }

    screenshots

    refs

    https://css-tricks.com/almanac/properties/b/box-shadow/

    https://www.cnblogs.com/xgqfrms/p/13264347.html

提交回复
热议问题