Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

I'm looking to recreate an effect like this with CSS 3D Transforms: 3D text

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?

Anyway, thanks in advance.

like image 565
hexagonest Avatar asked May 03 '15 01:05

hexagonest


People also ask

How do you make a 3D effect in CSS?

With the CSS transform property you can use the following 3D transformation methods: rotateX() rotateY() rotateZ()

How do you add effects to text in HTML?

HTML text effects are usually very simple to use, and you can change the text with just a small change in the code. To change size, just change the 24 (but leave the ” “) to any size you want. To change colors, replace #FF0000 with the new color you want.


2 Answers

Yes, ther solution to your problem is using transform-style: preserve-3d.

But the problem with this is that IE does not support this property

A way to make it work in IE is to use a pseudo element on the 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>
like image 111
vals Avatar answered Oct 14 '22 06:10

vals


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. This would be set to the parent element (in this case, .grid). I also use transform-origin:bottom to raise the text from inside the grid. 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>
like image 35
hexagonest Avatar answered Oct 14 '22 07:10

hexagonest