RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1564101
Accepted
danielilinskii
danielilinskii
Asked:2024-01-31 16:00:17 +0000 UTC2024-01-31 16:00:17 +0000 UTC 2024-01-31 16:00:17 +0000 UTC

可折叠立方体

  • 772

描述

大家好!我想制作一个立方体,当你将光标悬停在它上面时,它的边缘应该分开。您还需要在其边缘制作带有文本的箭头,当您悬停时,箭头应沿着其边缘移开,新文本将出现在下方。

.wrap {
  width: 1920px;
  position: relative;
  margin-top: 400px;
  perspective: 1000px;
  perspective-origin: 50% 50%;
}

.leg {
  position: relative;
  width: 0px;
  height: 100px;
  border: 1px solid black;
}

.fr,
.sc,
.th {
  position: relative;
}

.indicator {
  top: -85px;
  left: -170px;
  position: absolute;
}

.line {
  position: absolute;
  overflow: hidden;
  height: 300px;
  /* transform: rotate(45deg); */
}

.text {
  position: absolute;
  top: -120px;
  width: 100px;
}

.h-line {
  width: 100px;
  border: 1px solid black;
}

.d-line {
  margin-left: 86.5px;
  margin-top: 34px;
  width: 100px;
  border: 1px solid black;
  transform: rotate(45deg);
}

.cube {
  margin: auto;
  position: relative;
  height: 200px;
  width: 200px;
  transform-style: preserve-3d;
}

.cube>div {
  position: absolute;
  box-sizing: border-box;
  padding: 10px;
  height: 100%;
  width: 100%;
  opacity: 0.9;
  background-color: #000;
  border: solid 1px #eeeeee;
  color: #ff0000;
}

.legs {
  left: -65px;
  margin-top: 240px;
  position: absolute;
  display: flex;
  flex-direction: row;
  gap: 70px;
}

.sc {
  margin-left: 152px;
}

.th {
  margin-top: -78px;
}

.third {
  margin-top: 78px;
}

.front {
  transform: translateZ(100px);
}

.front--1 {
  transform: translateZ(100px);
}

.back {
  transform: translateZ(-100px) rotateY(180deg);
}

.right {
  transform: rotateY(-270deg) translateX(100px);
  transform-origin: top right;
}

.right--1 {
  transform: rotateY(-270deg) translateX(100px);
  transform-origin: top right;
}

.left {
  transform: rotateY(270deg) translateX(-100px);
  transform-origin: center left;
}

.top {
  transform: rotateX(-270deg) translateY(-100px);
  transform-origin: top center;
}

.top--1 {
  transform: rotateX(-270deg) translateY(-100px);
  transform-origin: top center;
}

.bottom {
  transform: rotateX(270deg) translateY(100px);
  transform-origin: bottom center;
}

.wrap:hover .front {
  transform: translateZ(200px) translateX(-200px);
  /*   margin-left: -200px;
    transition: 0.3s ease-in; */
  background-color: #fcf;
}

.wrap:hover .right {
  transform: rotateY(-270deg) translateZ(150px) translateX(150px);
}

.wrap:hover .top {
  transform: rotateX(-270deg) translateZ(120px) translateY(-100px);
}

.wrap:hover .bottom {
  transform: rotateX(270deg) translateZ(100px) translateY(100px);
}

.wrap:hover .legs {
  transform: translateY(100px);
  transition: transform 0.3s ease-in;
}

.wrap:not(:hover) .legs {
  transform: translateY(0);
  transition: transform 0.3s ease-in;
}

.wrap:hover .first {
  margin-top: 20px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .first {
  margin-top: 0;
  transition: 0.3s ease-in;
}

.wrap:hover .second {
  margin-top: 12px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .second {
  margin-top: 0;
  transition: 0.3s ease-in;
}

.wrap:hover .third {
  margin-top: -7px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .third {
  margin-top: 0;
  transition: 0.3s ease-in;
}

.wrap:hover .text {
  top: 5px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .text {
  top: -120px;
  transition: 0.3s ease-in;
}

.cube>div {
  transition: transform 0.3s ease-in;
}

.cube {
  transform: rotateX(-15deg) rotateY(-25deg);
}
<div class="wrap">
  <div class="cube">
    <div class="front">
      <div class="indicator">
        1
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Front side
    </div>
    <div class="front--1">
      Front side
    </div>
    <div class="top">
      <div class="indicator">
        2
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Top side
    </div>
    <div class="top--1">
      Top side
    </div>
    <div class="bottom">
      <div class="indicator">
        3
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Bottom side
    </div>
    <div class="right">
      <div class="indicator">
        4
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Right side
    </div>

    <div class="right--1">
      Right side
    </div>
    <section class="legs">
      <div class="fr">
        <div class="first leg"></div>
        <div class="indicator">
          4
          <div class="line">
            <div class="h-line"></div>
            <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
          </div>
          <div class="d-line"></div>
        </div>
      </div>
      <div class="sc">
        <div class="second leg"></div>
        <div class="indicator">
          4
          <div class="line">
            <div class="h-line"></div>
            <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
          </div>
          <div class="d-line"></div>
        </div>
      </div>
      <div class="th">
        <div class="third leg"></div>
        <div class="indicator">
          4
          <div class="line">
            <div class="h-line"></div>
            <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
          </div>
          <div class="d-line"></div>
        </div>
      </div>
    </section>
  </div>
</div>

问题

文本箭头不应与其所附着的立方体面位于同一平面,而应始终位于用户的正前方。
预先感谢您的合作!)

html
  • 1 1 个回答
  • 114 Views

1 个回答

  • Voted
  1. Best Answer
    De.Minov
    2024-02-02T05:15:27Z2024-02-02T05:15:27Z

    很高兴问题的作者能够在没有描述的情况下理解法官:)
    但我会尽力为那些可能觉得这个问题有用的人解释一切。

    如果您对某个元素应用 CSS 变换,那么它的子元素也会被变换,但如果您对它们应用反向变换值,那么它们将“正常”显示。

    让我们看一个例子skewX()

    body {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 40px;
      width: 100%;
      height: 100vh;
      margin: 0;
      overflow: hidden;
    }
    
    .box {
      display: block;
      width: 100px;
      height: 100px;
      background-color: red;
      transform: skewX(45deg);
    }
    
    .box-inner {
      display: block;
      width: 50px;
      height: 50px;
      background-color: blue;
      margin: 25px;
    }
    <div class="box">
      <div class="box-inner"></div>
    </div>
    
    <div class="box">
      <div class="box-inner" style="transform: skewX(-45deg)"></div>
    </div>

    从这个例子中可以看出,左边的红色和蓝色块具有相同的skewX().
    右侧的蓝色块被分配skewX(-45deg),即 其父级的反转值。
    因此,从视觉上看,蓝色块似乎不适合变形。

    “对齐”元素的工作方式与在 CSS 中使用 3D 时完全相同,只是这里需要应用更多值进行反转。

    首先,值得考虑的是它本身.cube也在空间中沿着轴 Ycube = 45deg 和 Xcube = -25deg 旋转。

    接下来,我们来看看侧面:

    X 边:沿 Y 轴旋转 90 度,因为 并沿同一轴旋转.cube,因此“正常”显示的值为rotateY(90deg - Ycube)。
    沿 X 的旋转将简单地反转rotateX(Xcube * -1);

    Y 边:沿 X 轴旋转 90 度,首先将这个值反转,然后将 Y 旋转Ycube * -1,然后沿 X 相对旋转.cube,这里值也会反转。

    Z 面:这基本上是已经处于“正常”位置的面,因此您只需反转立方体的旋转即可。

    为了在其他地方放置“提示”,您将需要其他值,您已经可以在此处选择它们。
    或者甚至编写一个mixin(如果使用预处理器),其中所有值都将从工具提示的方向和位置替换,并且其旋转将相对于立方体的侧面。


    这个立方体被用在 GIF 中:

    const x = document.querySelector('#rotateX')
    const y = document.querySelector('#rotateY')
    const cube = document.querySelector('.cube')
    
    const xInitialValue = x.value
    const yInitialValue = y.value
    
    const changeX = () => cube.style.setProperty('--Xcube', x.value+'deg')
    const changeY = () => cube.style.setProperty('--Ycube', y.value+'deg')
    
    changeX()
    changeY()
    
    x.addEventListener('mousemove', changeX)
    y.addEventListener('mousemove', changeY)
    
    x.addEventListener('contextmenu', (event) => {
      event.preventDefault()
      x.value = xInitialValue
      changeX()
    })
    y.addEventListener('contextmenu', (event) => {
      event.preventDefault()
      y.value = yInitialValue
      changeY()
    })
    body {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 100%;
      min-height: 100vh;
      background-color: #f2f2f2;
      font-family: sans-serif;
      color: #000;
      overflow: hidden auto;
      margin: 0;
      user-select: none;
    }
    
    #rotateY,
    #rotateX {
      position: fixed;
      z-index: 10;
    }
    
    #rotateY {
      width: 90%;
      height: 10px;
      top: 10px;
    }
    
    #rotateX {
      -webkit-appearance: slider-vertical;
      -moz-appearance: slider-vertical;
      appearance: slider-vertical;
      width: 10px;
      height: 45%;
      right: 10px;
    }
    
    .container {
      perspective: 700px;
    }
    
    .cube {
      display: block;
      width: 200px;
      height: 200px;
      --Xcube: -25deg;
      --Ycube: 45deg;
      transform: rotateX(var(--Xcube)) rotateY(var(--Ycube));
      transform-style: preserve-3d;
    }
    
    .cube * {
      transform-style: preserve-3d;
    }
    
    .cube-face {
      display: block;
      width: 200px;
      height: 200px;
      border: 5px dashed #333;
      background-color: rgba(0, 0, 0, 0.05);
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
      position: absolute;
    }
    
    .cube-face:hover .cube-hover {
      transform: translateZ(100px);
    }
    
    .cube-face--x {
      transform: translateX(-50%) rotateY(-90deg);
    }
    
    .cube-face--x-opposite {
      transform: translateX(50%) rotateY(90deg);
    }
    
    .cube-face--x .cube-face-normal {
      transform: rotateY(calc(90deg - var(--Ycube))) rotateX(calc(var(--Xcube) * -1));
    }
    
    .cube-face--x .cube-hover {
      background-color: rgba(255, 0, 0, 0.2);
      color: #f00;
    }
    
    .cube-face--y {
      transform: translateY(-50%) rotateX(90deg);
    }
    
    .cube-face--y-opposite {
      transform: translateY(50%) rotateX(-90deg);
    }
    
    .cube-face--y .cube-face-normal {
      transform: rotateX(-90deg) rotateY(calc(var(--Ycube) * -1)) rotateX(calc(var(--Xcube) * -1));
    }
    
    .cube-face--y .cube-hover {
      background-color: rgba(0, 128, 0, 0.2);
      color: #008000;
    }
    
    .cube-face--y .cube-hover-title {
      right: 0;
    }
    
    .cube-face--z {
      transform: rotateX(90deg) translateY(50%) rotateX(-90deg);
    }
    
    .cube-face--z-opposite {
      transform: rotateX(90deg) translateY(-50%) rotateX(90deg);
    }
    
    .cube-face--z .cube-face-normal {
      transform: rotateY(calc(var(--Ycube) * -1)) rotateX(calc(var(--Xcube) * -1));
    }
    
    .cube-face--z .cube-hover {
      background-color: rgba(0, 0, 255, 0.2);
      color: #00f;
    }
    
    .cube-hover {
      display: block;
      width: 100%;
      height: 100%;
      background-color: rgba(255, 0, 0, 0.1);
      transition: transform 0.3s ease;
      position: relative;
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
      pointer-events: none;
    }
    
    .cube-hover-title {
      display: block;
      width: 100px;
      height: 50px;
      background-image: 
        linear-gradient(#000 0 0), 
        linear-gradient(to top right, 
          transparent calc(50% - 1px), 
          #000 calc(50% - 1px), 
          #000 calc(50% + 1px), 
          transparent calc(50% + 1px)
        );
      background-repeat: no-repeat;
      background-position: 0 1em, 100% 1em;
      background-size: 70% 2px, 30% calc(100% - 1em);
      position: absolute;
      right: 100%;
      bottom: 100%;
      transform-origin: right bottom;
    }
    <input id="rotateY" type="range" min="-180" value="45" max="180" />
    <input id="rotateX" type="range" min="-90" value="-25" max="90" />
    
    <div class="container">
      <div class="cube">
        <div class="cube-face cube-face--x">
          <div class="cube-hover">
            <div class="cube-hover-title cube-face-normal">X face</div>
          </div>
        </div>
        <div class="cube-face cube-face--x-opposite"></div>
        <div class="cube-face cube-face--y">
          <div class="cube-hover">
            <div class="cube-hover-title cube-face-normal">Y face</div>
          </div>
        </div>
        <div class="cube-face cube-face--y-opposite"></div>
        <div class="cube-face cube-face--z">
          <div class="cube-hover">
            <div class="cube-hover-title cube-face-normal">Z face</div>
          </div>
        </div>
        <div class="cube-face cube-face--z-opposite"></div>
      </div>
    </div>

    顶部滑块 ( input[type="range"]) 负责旋转Y(水平),右侧滑块负责旋转X(垂直)。
    ПКМ滑块将重置为起始值。

    • 4

相关问题

  • 具有非均匀背景的块内的渐变边框

  • 离开页脚

  • 如何将三个字段的数据收集到一封电子邮件中?

  • Html 元素刚从父元素中出来

  • 如何在css中制作这个背景?

  • 如何制作带有斜条纹的背景?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5