How to position element in the correct 3d position with css perspective

前端 未结 1 1105
我寻月下人不归
我寻月下人不归 2021-01-23 06:00

I\'m trying to find a way to map an element, on top of a photo element that is placed at a given angle. The photo of a laptop is a good example, where I\'d like to map an elemen

相关标签:
1条回答
  • 2021-01-23 06:53

    perspective needs to be added to the parent, not to the child. The rest are details:

    span {
      background: green;
      width: 256px;
      height: 176px;
      position: absolute;
      top: 0;
      left: 0;
      transform: rotateX(1deg) rotateY(-7deg) rotateZ(-1deg) skew(-11.25deg, 1.5deg) translate(233px, 37px);
      opacity: 0.5;
    }
    
    div {
      position: relative;
      perspective: 400px;
      width: 1200px;
    }
    
    img {
      width: 500px;
      height: auto;
    }
    
    body {
      overflow-x: hidden;
    }
    <div>
      <span></span>
      <img src="https://i.stack.imgur.com/iL2xf.png" />
    </div>

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