gpt4 book ai didi

CSS 立方体,无法与网格对齐

转载 作者:行者123 更新时间:2023-11-28 10:18:15 27 4
gpt4 key购买 nike

所以我的目标是将这些立方体放在一个网格上,并让它们排成一行,可以拖动和捕捉。我根据 this example 使立方体运行良好,但我没有完全理解某些机制,因此遇到了一些问题。

  1. 立方体开始时比旋转后大。要查看此内容,只需单击应用“show-front”类的“1”,同时您仍在前面。它会立即收缩。 固定

  2. 立方体轴没有居中,所以当它旋转时,它会在不同的 xy 坐标处结束。

  3. 在 CSS 中,我将大小设置为 200x200(或 25 的任何系数),但由于 Z 变换,它并不完全正确。 这一个大部分已修复,请参阅底部的更新。

我该如何解决这三个问题?

这是 fiddle :http://jsfiddle.net/scottbeeson/phJpS/

这是重要的CSS部分:

    .itemView {
width: 200px;
height: 200px;
/*position: relative;*/
/*margin: 0 auto 40px;*/
/*border: 1px solid #CCC;*/
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-o-perspective: 1000px;
perspective: 1000px;
-webkit-margin-start: 0 !important;
-webkit-margin-before: 0 !important;
-webkit-margin-end: 0 !important;
-webkit-margin-after: 0 !important;
}

.cube {
width: 100%;
height: 100%;
position: absolute;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: -webkit-transform 1s;
-moz-transition: -moz-transform 1s;
-o-transition: -o-transform 1s;
transition: transform 1s;
}

.cube figure {
display: block;
position: absolute;
width: 196px;
height: 196px;
border: 2px solid black;
color: white;
}

.cube.panels-backface-invisible figure {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
}

.cube .front {
background-color: #555;
border: 1px solid #ccc;
}
.cube .back {
background-color: #555;
border: 1px solid #ccc;
}
.cube .right {
background-color: #555;
border: 1px solid #ccc;
}
.cube .left {
background-color: #555;
border: 1px solid #ccc;
}
.cube .top {
background-color: cornflowerblue;
border: 1px solid #ccc;
}
.cube .bottom {
background-color: #555;
border: 1px solid #ccc;
}

.cube .front {
-webkit-transform: translateZ( 99px );
}
.cube .back {
-webkit-transform: rotateX( -180deg ) translateZ( 99px );
}
.cube .right {
-webkit-transform: rotateY( 90deg ) translateZ( 99px );
}
.cube .left {
-webkit-transform: rotateY( -90deg ) translateZ( 99px );
}
.cube .top {
-webkit-transform: rotateX( 90deg ) translateZ( 99px );
}
.cube .bottom {
-webkit-transform: rotateX( -90deg ) translateZ( 99px );
}

.cube.show-front {
-webkit-transform: translateZ( -99px );
}
.cube.show-back {
-webkit-transform: translateZ( -99px ) rotateX( -180deg );
}
.cube.show-right {
-webkit-transform: translateZ( -99px ) rotateY( -90deg );
}
.cube.show-left {
-webkit-transform: translateZ( -99px ) rotateY( 90deg );
}
.cube.show-top {
-webkit-transform: translateZ( -99px ) rotateX( -90deg );
}
.cube.show-bottom {
-webkit-transform: translateZ( -99px ) rotateX( 90deg );
}

.itemHandle {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
cursor: move;
white-space: nowrap;
background-color: cornflowerblue;
text-align: left;
/*border-top-right-radius: 15px;*/
}

另外,如果有人觉得这些应该是单独的问题,那也没关系。我只是认为它们都是同一个“问题”的一部分,这比将同一个 fiddle 贴 3 次要容易。

#1、#3 更新 ( updated fiddle )

我能够将正面的 transformZ 更改为 0 并调整其余的变换,基本上使立方体的正面与“workArea”位于同一平面上。这样好多了,但是视角有点偏离,就好像你没有正面看立方体一样。除非面部是半透明的,否则不会引人注意。这是更新后的 CSS:

.cube .front  {
-webkit-transform: translateZ( 0px );
}
.cube .back {
-webkit-transform: rotateX( -180deg ) translateZ( 200px );
}
.cube .right {
-webkit-transform: rotateY( 90deg ) translateZ( 100px ) translateX(100px);
}
.cube .left {
-webkit-transform: rotateY( -90deg ) translateZ( 100px ) translateX(-100px);
}
.cube .top {
-webkit-transform: rotateX( 90deg ) translateZ( 100px ) translateY(-100px);
}
.cube .bottom {
-webkit-transform: rotateX( -90deg ) translateZ( 100px ) translateY(100px);
}

最佳答案

由于边距和填充,数字有偏差。

尝试:

.cube figure {
display: block;
position: absolute;
width: 200px;
height: 200px;
border: 0px solid black;
color: white;
margin: 0px;
padding: 0px;
}

添加的边距和填充 = 0

demo

我现在已经改变了整个坐标系。如果让立方体中心位于 0 0 坐标会更容易。现在所有旋转的东西只需要旋转,这更容易理解。

如果您真的希望正面位于 z=0 平面上,请在基础层设置一个全局偏移。

关于CSS 立方体,无法与网格对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com