html - :after pseudoelements wait to main item transition end 的 CSS3 过渡

标签 html css google-chrome css-transitions

我有一个简单的问题:如果我将 css 过渡附加到伪元素(:之后,:之前)和主要元素,伪元素的动画等待主要元素的动画结束。我想同时做两个动画。 我只在 FireFox (50.0.1) 的 Chrome (54.0.2840.99) 中遇到这个问题,它表现良好。

这个 fiddle 显示了问题: https://jsfiddle.net/CptCrunch/wtse7e8b/1

body {
  text-align: center;
}

a {
  font-size: 50px;
  font-weight: 800;
  color: red;
  text-decoration: none;
  transition: all 1s linear 0s;
}

a:hover {

  color: blue;
}

a::before {
  content: "\0005B";
  margin-right: 30px;
  transition: all 1s linear 0s;
 }

a::after {
  content: "\0005D";
  margin-left: 30px;
  transition: all 1s linear 0s;
}

有什么办法可以解决这个问题吗?感谢您的帮助。

最佳答案

如果您为每个元素设置特定的 transition 值(而不是使用 all),它的行为就像您在 Chrome 中预期的那样。我测试了 Firefox,它仍然可以正常工作。

a {
  font-size: 50px;
  font-weight: 800;
  color: red;
  text-decoration: none;
  transition: color 1s linear 0s; /*set color only*/
}

a:hover {
  color: blue;
}

a::before {
  content: "\0005B";
  margin-right: 30px;
  transition: margin 1s linear 0s; /*set margin only*/
 }

a::after {
  content: "\0005D";
  margin-left: 30px;
  transition: margin 1s linear 0s; /*set margin only*/
}

我有updated your js.fiddle here .希望对您有所帮助。

关于html - :after pseudoelements wait to main item transition end 的 CSS3 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40874352/

相关文章:

html - IE11 div 高度计算不正确

javascript - undefined variable : _SESSION

html - 无法显示带有过渡的文本

html - 菜单链接不向右浮动

javascript - 在 chrome 控制台上调试 javascript 函数

javascript - Google Chrome 上的结果不可预测

javascript - 需要在不影响父元素的情况下点击每个 li 元素

html - 在 Bootstrap 工具提示中强制换行

html - CSS3 : Multiple rotated divs vertically aligned

javascript - 使用 Puppeteer 捕获 HTTP 响应的正确方法是什么?