Antialiased text in Firefox after CSS rotation

前端 未结 2 1958
青春惊慌失措
青春惊慌失措 2021-01-06 08:45

\"enter

so I\'ve read a lot about the current state of rotating text and not being abl

2条回答
  •  误落风尘
    2021-01-06 09:11

    For whatever reason, it seems under some circumstances browsers "forget" to antialias text while doing complex transforms.

    The fix:

    Using CSS to force the browser to render the transformed element in a separately-composited "layer" is one solution:

    transform: rotate(…) translate3d(0px,0px,1px);
    

    The explanation:

    Many rendering engine implementations create a GPU layer for the 3d-transformed element, and composite it onto the rest of the page when painting. This alternate rendering path can force a different text-rendering strategy, resulting in better antialiasing.

    The caveat:

    However, this is a bit of a hack: first, we're asking for a 3-dimensional transform we don't really want; second, forcing many unnecessary GPU layers can degrade performance, especially on mobile platforms with limited RAM.

    dev.opera.com hosts a good discussion of compositing, hacks using transform3d, and the CSS3 will-change property.

提交回复
热议问题