Is it possible to “snap to pixel” after a CSS translate?

前端 未结 4 1815
谎友^
谎友^ 2021-02-01 15:15

I created a modal box and vertically centred it using a technique Chris Coyer mentioned. The only problem I\'ve found with it so far is that sometimes the box is offset by half

4条回答
  •  悲哀的现实
    2021-02-01 16:03

    In some browsers you can avoid 3d transforms and use 2d transforms instead, the translation will snap to pixels by default:

    transform: translate(-50%, -50%);
    

    rendering is snapped to pixels

    transform: translate3d(-50%, -50%, 0);
    

    rendering is anti-aliased

    JSBin: http://jsbin.com/epijal/3/edit

提交回复
热议问题