Only CSS rotate box-shadow without original element

前端 未结 2 1478
孤独总比滥情好
孤独总比滥情好 2021-01-24 18:08

I have a small problem, I want to create 45 degree shadow for a picture. But if I use my code my object is rotating too. So I would like to ask for help with this problem.

2条回答
  •  后悔当初
    2021-01-24 19:03

    You can do it using peudo-element (I've used arbitrary values, you need to tweak it yourself) :

    .item {
      margin-left: 50%;
      position: relative;
      width: 100px;
      height: 100px;
      background-color: red;
    }
    .item:before {
      z-index: -1;
      position: absolute;
      content: "";
      display: block;
      width: 100px;
      height: 100px;
      top: -30px;
      left: 0;
      background-color: transparent;
      box-shadow: -50px 120px 4px 10px #555;
      -webkit-transform: rotate(10deg);
      -moz-transform: rotate(10deg);
      -o-transform: rotate(10deg);
      -ms-transform: rotate(10deg);
      transform: rotate(10deg);
    }

提交回复
热议问题