Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font looks blurry after translate in Chrome

EDIT 2016-07-04(Since this question is getting popular): This is a bug in Chrome. Developers are actively working on a fix.

EDIT 2017-05-14 The bug seems to be fixed, the fix will be introduced in Chrome 60

EDIT 2018-05-04 A fix has been merged, but the bug still appears to be present.

So I have this very ugly-looking window that is centered on the screen by this CSS:

.popup
{
   position: fixed;
   top: 0;
   bottom: 0;

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

However, it looks like this on Chrome (the font looks really blurry):

Chrome

But like this on Firefox:

enter image description here

When I remove the transform rule, the text looks nice and crispy again, but then it's no longer correctly centered.

When I go to chrome://flags and execute #disable-direct-write it looks nicer, but users are obviously not going to do that and it doesn't solve the problem.

How can I make my font look nice while still having the window centered?

My chrome version is 44.0.2403.155

I have a three.js demo using WebGL that renders on a background canvas. When I disable the demo, the problem no longer occurs.

JSFiddle with the background.

JSFiddle without the background.

like image 337
joppiesaus Avatar asked Aug 16 '15 11:08

joppiesaus


People also ask

Why does my Chrome text look blurry?

Many users have been reporting that sometimes Chrome looks blurry. To fix that, you just need to clear your cache and browsing data. Resetting the browser settings to default can also help with these types of issues.

Why does my font look blurry?

Blurry font problems can be caused by cables that aren't connected properly, older monitors, and poor screen resolution settings.


Video Answer


6 Answers

A suggestion from a related discussion solved the issue for me: https://stackoverflow.com/a/46117022/7375996

Using calc with some offset solved the issue in my case:

transform: translate(calc(-50% + 0.5px), calc(-50% + 0.5px));
like image 145
Dmitry.Kolosov Avatar answered Oct 11 '22 22:10

Dmitry.Kolosov


I've tried different solutions in different, sometimes scary, combinations:

  • translate3d instead of translateY
  • zoom:2; transform: scale(0.5); or zoom:0.5; transform: scale(2);
  • transform: translate(calc(-50% + 0.5px), calc(-50% + 0.5px));
  • -webkit-filter: blur(0);
  • perspective: 1000px
  • scale(1.0, 1.0)
  • -webkit-font-smoothing: subpixel-antialiased;

none of them work in july 2019.

The only solution i found for modals, that should be centered - to use a flexbox aligment instead of transform: translate.

.modal__container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
}

  .modal {
    box-sizing: border-box;
    max-width: 80%;
    max-height: 80%;
    padding: 20px;
    overflow-y: auto;
    background: #fff;
  }
<div class="modal__container">
  <div class="modal">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
</div>
like image 27
Александр Михайлов Avatar answered Oct 11 '22 22:10

Александр Михайлов


Problem in half of pixel.

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

It will work!

like image 23
egor.xyz Avatar answered Oct 11 '22 22:10

egor.xyz


I found out -webkit-filter: blur(0) could fix your blurry font in Chrome on Windows:

JSFiddle

#projectPopup {
    ...
    -webkit-filter: blur(0);
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}
like image 32
sergdenisov Avatar answered Oct 11 '22 21:10

sergdenisov


Use a normalization of the transform after your animation:

Transform X/Y normalization

Or We scale the texture with zoom double, then scale down again. In some cases this cannot be applied due to other complex transformations or translations, and is not perfect.

...{
zoom:2;
-webkit-transform: scale(0.5);
transform: scale(0.5);
}
like image 1
Miguel Avatar answered Oct 11 '22 20:10

Miguel


The height of the elements must be even numbers https://prnt.sc/mtxxa2

like image 1
user3382357 Avatar answered Oct 11 '22 20:10

user3382357