Text blurry after 3D transform

前端 未结 1 684
情话喂你
情话喂你 2020-12-05 11:40

I have a div that I\'ve rotated around the X-axis with perspective. The div contains text that gets blurry when the rotation is applied. Is there any way to get the text sha

相关标签:
1条回答
  • 2020-12-05 12:27

    Here is a workaround to make the text less blurry. It doesn't make it pixel perfect but it is better. Tested on chrome 38 FF 32 and IE 11 windows 7.

    The point is to scale the text up (x2) with font-size (in the example fiddle I also scaled the width/height of the container) and scale it back down with transform: scale(0.5);. The text is rendered with less blur than the 1:1 default scaling ratio.

    Here is a screenshot (chrome 38) of both fiddles :

    Less blurry text with 3D transform

    And a DEMO

    CSS :

    .tilt {
        margin: -200px auto 0;
        width: 600px;
        height:800px;
        font-size:2em;
        border: 2px solid #222;
    
    
        -webkit-transform: perspective(500px) rotateX(35deg) scale(0.5);
           -moz-transform: perspective(500px) rotateX(35deg) scale(0.5);
                transform: perspective(500px) rotateX(35deg) scale(0.5);
    }
    

    Scale ratio optimization :

    When the text has the default scale ratio, it is blured as we can see in the original OP fiddle. When you scale the text with a 0.1 ratio the text becomes aliased with pixel rendering bugs :

    Aliased text after 3d transform and a 0.1 scale ratio

    DEMO

    The point is to find the best compromise between aliased and blured text. For the OP example, 0.5 gives a good result but I am sure it can be optimized.


    As suggested by John Grivas, you can also add a 1px text-shadow that tends to make the middle and top lines render better :

    text-shadow: 0 0 1px #101010;
    

    DEMO


    As commented by Mary Melody, some fonts render better than others, you can check this DEMO with the most popular google fonts.

    0 讨论(0)
提交回复
热议问题