简体   繁体   English

如何使用Css3变换创建一个站立的3D文本效果

[英]How to create a standing up 3D text effect with Css3 transforms

I'm looking to recreate an effect like this with CSS 3D Transforms: 我想用CSS 3D Transforms重新创建这样的效果: 3D文字

How do I achieve this? 我该如何实现这一目标? Here's what I've got so far 这是我到目前为止所得到的

 body { perspective: 400px; transition: perspective 1s; } .grid { display: flex; justify-content: center; align-items: center; background-image: url("http://i.imgur.com/3ACizko.jpg"); background-size: cover; height: 400px; width: 400px; transform: rotateX(60deg); margin: 0 auto; transition: transform 1s; perspective: 400px; } .grid p { transition: transform 1s; transform: rotateX(-60deg); } 
 <div class="grid"> <p>Hello</p> </div> 

I thought that if I rotated the background surface 60 degrees and rotated the text -60 degrees it would cancel out the effect but apparently not? 我想如果我将背景表面旋转60度并旋转文字-60度它会取消效果但显然不是?

Anyway, thanks in advance. 无论如何,提前谢谢。

Yes, ther solution to your problem is using transform-style: preserve-3d. 是的,您的问题的解决方案是使用transform-style:preserve-3d。

But the problem with this is that IE does not support this property 但问题是IE不支持这个属性

A way to make it work in IE is to use a pseudo element on the p 使其在IE中工作的一种方法是在p上使用伪元素

 .grid { font-size: 30px; position: relative; left: 100px; top: 200px; perspective: 200px; perspective-origin: 0% 50%; } .grid:after { content: ""; position: absolute; width: 300px; height: 200px; top: -100px; left: -100px; transform: rotateX(30deg); background-image: repeating-linear-gradient(0deg, transparent 0px, transparent 47px, black 47px, black 50px), repeating-linear-gradient(90deg, transparent 0px, transparent 47px, black 47px, black 50px); } 
 <p class="grid">Hello</p> 

After a bit of research, I am confident to post my own answer. 经过一番研究,我有信心发表自己的答案。

This effect can be achieved using the transform-style property, and setting it to preserve-3d . 可以使用transform-style属性将其设置为preserve-3d来实现此效果。 This would be set to the parent element (in this case, .grid). 这将设置为父元素(在本例中为.grid)。 I also use transform-origin:bottom to raise the text from inside the grid. 我还使用transform-origin:bottom来从网格内部引发文本。 Here's the snippet: 这是片段:

 body { perspective: 400px; transition: perspective 1s; } .grid { display: flex; justify-content: center; align-items: center; background-image: url("http://i.imgur.com/3ACizko.jpg"); background-size: cover; height: 400px; width: 400px; transform: rotateX(60deg); margin: 0 auto; transition: transform 1s; perspective: 400px; transform-style:preserve-3d; } .grid p { transition: transform 1s; transform-origin:bottom; transform: rotateX(-60deg); } 
 <div class="grid"> <p>Hello</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM