CSS3 匹配 3d 形状(立方体顶部)

标签 css 3d shapes

我不擅长数学和几何,所以如果有人能帮助我创建以下形状,我会很高兴:

shape

所以基本上形状存在于 3 个矩形中,我得到前两个与变换矩阵完美配合,但我无法得到最后一个匹配形状(请参见上面的 img 链接)

JSFiddle, what I tried so far or see code below

HTML

<div class="shape">
  <div class="shape-rect-one"></div>
  <div class="shape-rect-two"></div>
  <div class="shape-rect-three"></div>
</div>​

CSS

.shape {
  perspective: 1000px;
}

.shape div {
  width: 100px;
  height: 100px;
  opacity: 0.4;
  background-color: #333;
}

.shape-rect-one {
  z-index: 100;

  transform: matrix(1, -0.40, 0, 1, 0, 0);
  -webkit-transform: matrix(1, -0.40, 0, 1, 0, 0);
}

.shape-rect-two {
  z-index: 200;

  transform: matrix(1, -0.40, 0, 1, 0, 0);
  -webkit-transform: matrix(1, 0.40, 0, 1, 0, 0);
}

.shape-rect-three {
  z-index: 300;
}​

最佳答案

你可以用一种更简单的方式来做到这一点,只需要一个元素。

DEMO

结果:

6 point star

HTML:

<div class='piece'></div>

相关CSS:

.piece {
  width: 10em; height: 8.66em; /* 10*sqrt(3)/2 = 8.66 */
  background: rgba(0,0,0,.5);
}
.piece {
  position: relative;
  transform: rotate(-30deg) skewX(30deg);
}
.piece:before, .piece:after {
  position: absolute;
  width: inherit; height: inherit;
  background: inherit;
  content: '';
}
.piece:before { transform: skewX(-30deg) skewX(-30deg); }
.piece:after { transform: skewX(-30deg) rotate(-60deg) skewX(-30deg); }

关于CSS3 匹配 3d 形状(立方体顶部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13314596/

相关文章:

html - 带变量的 CSS3 计算

r - 如何使用更少的包绘制二元正态分布的表面和轮廓

javascript - 如何反转在​​ CylinderGeometry 对象中应用纹理的方向?

java - 在 Java 中解析十六进制值

excel - 保护形状,以便用户可以修改但不能删除

Java矩形检测

html - 如何让盒子根据其内容增加其大小?

javascript - 如何围绕字形的垂直中间或中心点应用 CSS 旋转过渡

javascript - 如何获取内联样式去除除数字以外的所有文本?

matlab - 我怎样才能在 MATLAB 中重现这个长方体图?