formular to calculate width/height (relative to parent) of container with translateZ inside of parent container with perspective

前端 未结 3 657
借酒劲吻你
借酒劲吻你 2020-12-16 16:00

What is the formular to calculate the widths/heights of child elements with translateZ inside of parent container with set perspective (keyword: &

3条回答
  •  青春惊慌失措
    2020-12-16 16:31

    I have changed the style slightly, to make things more visible.

    The result seems ok for me. May be I am misunderstanding something?

    html, body {
      height: 100%;
      overflow: hidden;
      width: 100%;
    }
    
    #projection {
      perspective: 1px;
      perspective-origin: 0 0;
      height: 50%;
      overflow: visible;
      width: 50%;
      margin-left: 50px;
      background-color: grey;
    }
    
    .pro {
      transform: scale(1) translate(0px, 0px) translateZ(0px);
      height: 50%;
      position: absolute;
      transform-origin: 0 0;
      transform-style: preserve-3d;
      width: 100%;
    }
    
    .pro--1 {
      transform: scale(4) translate(0px, 0px) translateZ(-3px);
      width: 110%;
    }
    
    .pro--2 {
      transform: scale(3) translate(0px, 120%) translateZ(-2px);
      width: 110%;
    }
    
    .pro--3 {
      transform: scale(2) translate(0px, 240%) translateZ(-1px);
      width: 110%;
    }
    
    .pro--1 {
      background: rgba(0, 0, 75, 0.5);
      color: blue;
      line-height: 1em;
      text-align: center;
    }
    
    .pro--2 {
      background: rgba(0, 75, 0, 0.5);
      color: green;
      line-height: 4em;
    }
    
    .pro--3 {
      background: rgba(75, 0, 0, 0.5);
      color: red;
      line-height: 7em;
    }
    pro--1
    pro--2
    pro--3

提交回复
热议问题