CSS-反旋转式旋转效果
因此,我想创建一组满足以下属性的按钮:
- 形状是梯形的等化属性(目前是通过
transform:perspective:perspective(200px)rotatex(-35deg)(-35deg)
- hover,intust intut颜色和文本颜色交换(目前是通过悬挂代码实现的)
- 按钮文本没有旋转(目前是通过反旋转来实现的
rotatex(35DEG)
在跨越)
到目前为止,它们看起来像这样: 悬停之前的按钮
但是,在悬停时,发生这种情况,这发生了所有按钮:
在我的测试中,是由代码的 btn-trapezoid-outline跨度范围
部分引起的,但是将其删除使文本以某种方式旋转。您对如何修复有任何想法吗?
相关代码如下:
body {
width: 100%;
height: 100%;
position: fixed;
background: #121212;
text-align: center;
padding-top: 50px;
}
.btn-wrap{
margin: 25px 0px;
width:100%;
text-align: center;
}
.btn{
font-family: sans-serif;
text-transform: uppercase;
text-decoration: none;
}
.btn-trapezoid-outline{
display: inline-block;
color: #fcec0c;
transform-style: preserve-3d;
padding: 20px 40px;
border: 1px solid #fcec0c;
transform: perspective(200px) rotateX(35deg) translateZ(25px) translateY(14.4px);
-webkit-backface-visibility: hidden;
transition: all .3s ease-out;
margin: 0px 30px;
}
.btn-trapezoid-outline span {
display:inline-block;
transform:perspective(200px) rotateX(-35deg);
/* Safari */
-webkit-transform: rotateX(-35deg);
/* Firefox */
-moz-transform: rotateX(-35deg);
/* Opera */
-o-transform: rotateX(-35deg);
/* IE */
-ms-transform: rotateX(-35deg);
}
.btn-trapezoid-outline:hover{
background: #fcec0c;
color: #121212;
}
谢谢, 标记
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
转换风格移动:Preserve-3D;
转移到.btn-Trapezoid-Outline
的父母。由于您在该元素本身上应用转换和观点,因此它仅保留其子元素的3D,而它仍然在平坦的空间中,这里是源文档,解释了原因: https://developer.mozilla.org/en-us/docs/web/css/transform-style
Try moving the
transform-style: preserve-3d;
to the parent of.btn-trapezoid-outline
. Since you are applying transform and perspective on that element itself, it is only preserving 3d of its child elements, while it remains in a flat spaceHere is the source documentation that explains why: https://developer.mozilla.org/en-US/docs/Web/CSS/transform-style
转换风格的CSS属性设置了元素的子女是位于3D空间中还是在元素平面中扁平。
所以我认为您需要转换风格: Preserve-3D;我认为这是“ .btn”,
我认为这是“ .btn”,这是不需要做梯形形状的,因为它可以轻松完成
编辑:如果由于某种原因仍然要使用相同的代码,则可以使用Translatey(-10px)跨越悬停在悬停求解此问题
The transform-style CSS property sets whether children of an element are positioned in the 3D space or are flattened in the plane of the element.
https://developer.mozilla.org/en-US/docs/Web/CSS/transform-style
so I think you need transform-style: preserve-3d; set to parent, I am guessing it is ".btn"
In my opinion it's all unnecessary to make Trapezoid shape because it can be done easily
https://css-tricks.com/the-shapes-of-css/
Edit: If you still want to use the same code for some reason, you can use translateY(-10px) to span on hover solve this quickly