我对css样式和在浏览器中放大缩小都有一个有趣而奇怪的问题.

我创建了一个material ui卡,用它可以在单击动画时更改背景 colored颜色 .

动画效果很好,但若放大或缩小页面,浏览器会以某些zoom 值百分比呈现间隙.

enter image description here

我在寻找解决方案的过程中也看到过一些类似的情况,但没有一个是有效的,甚至有人说你对这种问题无能为力.示例:Rendering (rounding?) issue in Chrome when zooming

欢迎提供任何建议或帮助.我为此奋斗了几天:P

I have prepared some demo https://codesandbox.io/s/animate-divs-forked-1b3v4g. It seems that making a container simple div or a card from material ui and using border-radius: 0px makes no difference, the gap still occurs, mostly in browsers other than mozilla firefox. Just click container, zoom in or out in chrome or edge and you will see it. EDIT: changing border-bottom as even pixel number seems to help at some zooms level (50%?) but not all. On firefox everything is fine. enter image description here

推荐答案

try 删除BigDiv类中的border属性并创建第二个伪类.我认为这可能是一个blink engine渲染问题.

BigDiv class

display: flex;
min-width: 220px;
height: 100%;
position: relative;
padding: ${theme.spacing(2, 0)};
border-bottom: orange 5px solid; /* remove this */
background-color: transparent;
cursor: pointer;
text-align: center;
transition-delay: 0.5s;
will-change: transform;

/* Add this */
::before {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 4px;
  background-color: orange;
}

document.addEventListener('DOMContentLoaded', function() {
  const click = document.querySelector('.big');
  const click2 = document.querySelector('.big2');

  click.addEventListener('click', e => {
    e.currentTarget.classList.toggle('active');
  });
  click2.addEventListener('click', e => {
    e.currentTarget.classList.toggle('active');
  });
});
.big,
.big2 {
  width: 220px;
  height: 100%;
  position: relative;
  padding: 1rem 2rem;
  background-color: transparent;
  cursor: pointer;
  text-align: center;
  transition-delay: 0.5s;
  will-change: transform;
}

.big {
  border-bottom: orange 4px solid;
}

.big::after,
.big2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: orange;
  animation: out 0.5s ease-in-out forwards;
  transform-origin: bottom center;
}

.big2::before {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 4px;
  background-color: orange;
}

.big.active::after,
.big2.active::after {
  animation: in 0.5s ease-in-out forwards;
}

.second {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  z-index: 1;
}

@keyframes in {
  0% {
    transform: scaleY(0);
    background-color: transparent;
  }
  100% {
    transform: scaleY(1);
    background-color: orange;
  }
}

@keyframes out {
  0% {
    transform: scaleY(1);
    background-color: orange;
  }
  100% {
    transform: scaleY(0);
    background-color: transparent;
  }
}
<div class="big">
  <div class="second">
    <p>Click to animate with border</p>
  </div>
</div>
<div class="big2">
  <div class="second">
    <p>Click to animate  pseudo-class</p>
  </div>
</div>

Javascript相关问答推荐

JavaScript .Click()函数不起作用

如何保持子画布元素的1:1宽高比?

*ngFor和@代表输入decorator 和选角闭合

vanillajs-datepicker未设置输入值,日期单击时未触发更改事件

使用TMS Web Core中的HTML模板中的参数调用过程

判断表格单元格中是否存在文本框

当点击注册页面上的注册按钮时,邮箱重复

使用Java脚本根据按下的按钮更改S文本

我的角模板订阅后不刷新'

S文本内容和值不必要的不同

JQuery Click事件不适用于动态创建的按钮

检索相加到点的子项

如何 for each 输入动态设置输入变更值

如何使用基于promise (非事件emits 器)的方法来传输数据?

MongoDB受困于太多的数据

当从其他文件创建类实例时,为什么工作线程不工作?

是否可以在不更改组件标识的情况下换出Reaction组件定义(以维护状态/引用等)?如果是这样的话,是如何做到的呢?

Promise.race()返回已解析的promise ,而不是第一个被拒绝的promise

Chrome上的印度时区名S有问题吗?

我如何才能获得价值观察家&对象&S的价值?