CSS transform: translate(-50%,-50%)导致的像素模糊问题解决办法

发布日期: 2020-11-27 00:00:00
点击次数: 4069
大字 小字

三、解决办法

方式有二

第一种: 在 transfrom 时,使用 calc 函数 加上0.5 px ,具体代码 : 



  1.  
    .modal {
  2.  
     
  3.  
    position: absolute;
  4.  
    top: 50%;
  5.  
    right: 50%;
  6.  
    margin: auto;
  7.  
    /** 这 0.5px加或者减都可以 */
  8.  
    transform: translat(calc(-50% + 0.5 px), calc(-50% + 0.5 px));
  9.  
    }

第二种,别 transform 了,直接父元素弄成 Flex 布局,两条轴都设置居中,也能达到效果。

返回顶部