排列立方体面的z-index

时间:2015-02-02 02:39:06

标签: html css jquery-ui

如何排列彼此重叠的立方体的面。在这里,我发现了一个在IE中工作的立方体我现在的问题是立方体的面是透明的,所以当我把图像放到它上面时,它会相互重叠。

提前谢谢。

这是输出:http://codepen.io/anon/pen/VYMapx 这是css:

p {
  font: 700 1.5em trebuchet ms, century gothic, verdana, sans-serif;
}

.cube, .cube * {
  position: absolute;
  top: 50%;
  left: 50%;
}

.cube {
  user-select: none;
  cursor: move;
}

.face {
  box-sizing: border-box;
  border: solid 1px;
  margin: -8em;
  width: 16em;
  height: 16em;
  /** backface-visibility: hidden; /**/
}
.face:nth-child(1) {
  background: red;
}
.face:nth-child(2) {
  background: yellow;
}
.face:nth-child(3) {
  background: lime;
}
.face:nth-child(4) {
  background: cyan;
}
.face:nth-child(5) {
  background: blue;
}
.face:nth-child(6) {
  background: magenta;
}

1 个答案:

答案 0 :(得分:2)

只需将transform-style: preserve-3d;添加到.cube元素:

.cube {
  user-select: none;
  cursor: move;
          transform-style: preserve-3d;
       -o-transform-style: preserve-3d;
      -ms-transform-style: preserve-3d;
     -moz-transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

还取消注释(提供)backface-visibility:hidden; for opaque Faces

<强> jsBin demo (tested in IE)

文档:https://developer.mozilla.org/en-US/docs/Web/CSS/transform-style