用css3写webpack的主页Logo?

就是目标是这样的
image.png
我目前是做出来这样的
image.png
想问一下里边的小盒子怎么能盖住大盒子的部分位置
image.png

如果改变html的dom结构先写outer再写inner的话,旋转的时候会出问题,而且本来遮盖出来的颜色也没有了

  <div class="box">
    <ul class="outer">
      <li class="top"></li>
      <li class="bottom"></li>
      <li class="font"></li>
      <li class="back"></li>
      <li class="left"></li>
      <li class="right"></li>
    </ul>
    <ul class="inner">
      <li class="top"></li>
      <li class="bottom"></li>
      <li class="font"></li>
      <li class="back"></li>
      <li class="left"></li>
      <li class="right"></li>
    </ul>
  </div>

image.png
而且边框是怎么判断的外边加粗
image.png
呜呜呜....

阅读 1.4k
1 个回答

其实是挺简单的拉,整体旋转就可以了。

  • 面向屏幕的这几个面背景色为透明或者空即可。
  • 边框变粗的问题,就是对应边加粗就好了。

image.png

最近总是打不开Codepen所以就不提供在线Demo了,直接复制下方代码段在本地复现:

<!-- html结构 -->
<div class="cube outer">
  <div class="face front"></div>
  <div class="face back"></div>
  <div class="face top"></div>
  <div class="face bottom"></div>
  <div class="face left"></div>
  <div class="face right"></div>
  <div class="cube inner">
    <div class="face front"></div>
    <div class="face back"></div>
    <div class="face top"></div>
    <div class="face bottom"></div>
    <div class="face left"></div>
    <div class="face right"></div>
  </div>
</div>
// CSS样式
body{
  background: #2b3a42;
}
:root {
  --depth: 50px;
}
.cube {
  width: 100px;
  height: 100px;
  position: relative;
  transform-style: preserve-3d;
  transform: translate(-50%,-50%) rotateX(-35deg) rotateY(-135deg) translateZ(var(--depth));
  position: absolute;
  top: 50%;
  left: 50%;
}
.face {
  position: absolute;
  width: 100px;
  height: 100px;
  box-sizing: border-box;
  z-index: -1;
} 
.front {
  transform: translateZ(var(--depth));
}
.back {
  transform: rotateY(180deg) translateZ(var(--depth));
}
.top {
  transform: rotateX(90deg) translateZ(var(--depth));
}
.bottom {
  transform: rotateX(-90deg) translateZ(var(--depth));
}
.left {
  transform: rotateY(-90deg) translateZ(var(--depth));
}
.right {
  transform: rotateY(90deg) translateZ(var(--depth));
}
.outer > .face{
  background: #75afcc;
  border: 1px solid white;
}
.outer > .back {
  background: none;
  border-width: 0.5px;
  border-right-width: 5px;
  border-bottom-width: 5px;
  z-index: 100
}
.outer > .top {
  background: none;
  border-width: 0.5px;
  border-left-width: 5px;
  border-bottom-width: 5px;
  z-index: 100
}
.outer > .right {
  background: none;
  border-width: 0.5px;
  border-left-width: 5px;
  border-bottom-width: 5px;
  z-index: 100
}
.inner {
  width: 50px;
  height: 50px;
  transform: translate(-50%,-50%)
}
.inner > .face{
  --depth: 25px;
  width: 50px;
  height: 50px;
  background: #5299c8;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题