Here's a better solution:
- use
perspective
on the parent of the three children - set
transform-origin
buttombottom
on the first child - set
transform-origin
top
on the third child - use CSS
rotate
to i.e:53deg45deg
on the X axis with values1
(first child) and-1
(third child)
.words {
font-size: 2rem;
text-align: center;
perspective: 1000px; /* add perspective to the parent */
width: max-content;
margin: auto;
> div {
text-align: center;
padding: 1rem;
background: #ddd;
outline: 2px solid red;
&:nth-child(1) {
transform-origin: bottom;
rotate: 1 0 0 45deg; /* x y z angle */
}
&:nth-child(3) {
transform-origin: top;
rotate: -1 0 0 45deg;
}
}
}
<div class="words">
<div>Turn this</div>
<div>into</div>
<div>something</div>
</div>
No need to create extra useless wrapping DIVs.