12

I have a centered form on my page positioned using top and left values and css3 transformations.

<div class="middle">
    <h1>This is blurry, or should be.</h1>
</div>

.middle {
    position: absolute;
    top: 50%;
    left: 50%;
    min-width: 390px;

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

    /** backface-visibility: hidden; **/
}

h1 {
    padding-bottom: 5px;
    border-bottom: 3px solid blue
}

Notice backface-visibility. When set to hidden, all problems are solved for me using chrome 42. It doesn't render blurry. For others however using the same chrome version, it renders blurry with it.

Here's what it looks like without BV: http://jsfiddle.net/mzws2fnp/

enter image description here

To you it may be blurry, to others it may not.

Here's what it looks like with BV: http://jsfiddle.net/mzws2fnp/2/

enter image description here

For some reason people see the border blurry however I do not. I know backface-visibility: hidden is meant to fix that, and it does for me, just not for others using the same browser as I. Strange.

davidxd33
  • 1,186
  • 4
  • 22
  • 38
  • What effect are you looking for, what is the desired behavior? – apaul Apr 09 '15 at 15:59
  • For it not to be blurry for everyone? – davidxd33 Apr 09 '15 at 16:35
  • Possible duplicate of [Font looks blurry after translate in Chrome](http://stackoverflow.com/questions/32034574/font-looks-blurry-after-translate-in-chrome) – joppiesaus Apr 01 '16 at 19:45
  • The solutions in [Font looks blurry after translate in Chrome](http://stackoverflow.com/questions/32034574/font-looks-blurry-after-translate-in-chrome) doesn't work for this issue – Vinicius Coelho Apr 20 '16 at 12:58

8 Answers8

9

Try -50.1%

 transform: translateY(-50%) translateX(-50.1%);

EDIT: I have found out, they are blurred when chrome dev tools are opened, try to close them and refresh

youbetternot
  • 2,566
  • 2
  • 17
  • 20
  • 1
    @ViniciusCoelho I have found out, they are blurred when chrome dev tools are opened, try to close them and refresh – youbetternot Apr 20 '16 at 13:45
  • 1
    Strangely, for me, it was blurred with dev tools open or not. Your solution to change it to `-50.1%` worked for me. – Sean Whelan Aug 14 '17 at 19:59
  • 1
    2019 and it's still blurring out for me. Seems like closing dev tools prevents it from happening. Thankfully it's a browser bug, I mean, there's always a lot of weird stuff going on when the dev tools is open, especially in IE and Edge – Abana Clara Jan 23 '19 at 08:29
2

This is a bug in Google Chrome. I reported this issue to Google:

Rendering bug in css transform: it blurrs borders

<div class="middle">
    <input type="text" />
</div>
.middle {
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translateY(-50%) translateX(-50%);
    transform: translateY(-50%) translateX(-50%);
}
input {
    border: 1px solid black;
    border-radius: 4px;
}
var middle = document.querySelector('.middle');
setInterval(function(){
    middle.style.paddingTop = middle.style.paddingTop === "0px" ? "1px" : "0px";
}, 1000);

Animated bug demonstration

user1613797
  • 1,197
  • 3
  • 18
  • 33
  • 1
    A year later, this still seems to be an issue. I'm aware that it's not so much Chrome messing up as other browsers just putting in more effort to compensate half units but it's still frustrating that no easy workaround exists. – Lawyerson May 26 '16 at 10:32
1

When you use percentage, will play an odd number. will blurry borders, using parseInt to assign the value is integer.

$(document).ready(function(){


   $('.middle').css({ 
            'top':parseInt($('.middle').position().top)+ 'px', 
            'left': parseInt($('.middle').position().left)+'px',
            'transform':'none',
            '-webkit-transform':'none' 
            });

});
.middle {
position: absolute;
top: 30%;
left: 50%;
min-width: 390px;

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

h1 {
padding-bottom: 5px;
border-bottom: 4px solid blue}

.middle2 {
position: absolute;
top: 70%;
left: 50%;
min-width: 390px;

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

h1 {
padding-bottom: 5px;
border-bottom: 4px solid blue}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="middle">
<h1>This is blurry, or should be.</h1>
</div>


<div class="middle2">
<h1>This is blurry, or should be.</h1>
</div>
1

In this specific case where you're using a solid border, you can try using a box-shadow instead of a border as a workaround. For example, replace: border-bottom: 3px solid blue; with box-shadow: 0px 3px 0px blue;

1

Use even number (2px or 4px) for the border. Odd number (3px or 5px) is giving that blur.

border-bottom: 4px solid blue;
0

there is little hack that can help to get any block as center middle. in parent <div> where we add position: relative add below properties,

display: flex;
justify-content: center;

now add align-self: center; property with the block which we want to make center middle make sure that this block is absolute position.

0

Because translated element height is odd number. This will not occur when element height is even number.

-2

This problem occurs when we add

transform: translateY(-50%) translateX(-50%);

OR

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

it is still as an open issue in chromium bugs list.