I noticed that there is a big quality difference when transforming text in this 2 ways:
.text1 {
width: 200px;
height: 22px;
position: absolute;
top: 40%;
left: 0;
transform-origin: 50% 50%;
transform: scale(2); /* here */
color: red;
text-align: center;
font-size: 22px;
}
.text2 {
width: 200px;
height: 22px;
position: absolute;
top: 60%;
left: 0;
transform-origin: 50% 50%;
transform: translateZ(400px); /* here */
text-align: center;
font-size: 22px;
}
.perspective {
width: 200px;
height: 200px;
perspective: 800px;
transform-style: preserve-3d;
}
<div class="perspective">
<div class="text1">Text</div>
<div class="text2">Text</div>
</div>
Is there a way to force a better rendering when displacing text on the Z axis?
the reason the text blurs when you're transforming with
translateZ(400px)
is that this is a 3D transformation ; the browser treats the element as textures instead of vectors in order to provide hardware 3d acceleration.So basically the resolution will be lower when increasing size.
On the other hand transforming with scale is a 2D transformation, the browser treats the element as vector and blurring doesn't occur.
take a look at what happens to
scale
as soon as we kick in with 3d, without actually setting anytranslateZ
value:the only workaround I can think of at the moment is checking the stylesheet through JS and overriding
translateZ
withtransform: scale
fiddle
As you can see, even if it does work, a lot of optimization is needed.. (I wouldn't consider it production ready in it's current state ).
You can add font-smooth (for firefox), and antialiasing for webkit
https://developer.mozilla.org/en-US/docs/Web/CSS/font-smooth
http://davidwalsh.name/font-smoothing