【问题标题】:-webkit-background-clip: text on an element with transition is not working after the transition is over in mozilla but working perfect in chrome-webkit-background-clip:在 mozilla 中过渡结束后,带有过渡的元素上的文本不起作用,但在 chrome 中完美运行
【发布时间】:2019-04-17 23:51:14
【问题描述】:

我在一个元素上应用了 -webkit-background-clip: text 属性。该元素也具有过渡属性。 webkit 背景剪辑属性在过渡期间工作正常,但在过渡结束后,它在 mozilla firefox 中不再工作,但在 chrome 中工作正常。请帮我解决这个问题。

当我使用动画属性代替过渡时,效果很好。但我对过渡属性很好奇。 编辑:如果我不使用过渡属性,sn-p 在 mozilla web xbrowser 中可以正常工作。

我希望在 Firefox 中过渡结束后渐变保留在文本上。

div {
  height: 200px;
  margin-top: 2rem;
  padding-right: 3rem;
  padding-bottom: 1.5rem;
  display: inline-block;
  font-size: 10rem;
  position: relative;
  background-image: linear-gradient(to right, red, green, blue, gold, pink, violet, purple);
  -webkit-background-clip: text;
  color: transparent;
  border: 1px solid red;
  transition: transform 3s;
}

div:hover {
  transform: translateX(500px);
}
<div>Test</div>

CodePen

【问题讨论】:

标签: html css firefox


【解决方案1】:

您似乎遇到了 Firefox 错误。问题似乎与transition 无关,但从基于您的sn-p 的测试来看,Firefox 似乎拒绝呈现被翻译超过其一半宽度的元素的-webkit-background-clip: text

onload=function(){
document.querySelectorAll('input').forEach(i=>i.oninput())}
#t {
  display: inline-block;
  background-image: linear-gradient(to right, red, red);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  transform: translateX(61px);

  outline: 1px solid red;
  font-size: 100px;
  color: green;
  font-family: monospace
}
  <div id="t"></div>
<p>
  Translate: <input type="range" min="0" max="600" value="30" step="1" oninput="t.style.transform='translateX('+this.value+'px)';tr.value=this.value"> <output id="tr"></output>
  <br>
  Content: <input type="text" value="a" oninput="t.textContent=this.value;w.value=getComputedStyle(t).width"><br>
  Width: <output id="w"></output>


错误提交:https://bugzilla.mozilla.org/show_bug.cgi?id=1545128

【讨论】:

  • (由于这不是答案,而只是来自问题的精炼信息,如果您觉得它与问题匹配,请随时将其容纳在那里,我将删除它。同时我会寻找 /填写错误报告。)
  • 你解释的很好,我不知道它的根本原因。谢谢你。现在我知道为什么会这样了。
  • 我尝试更改容器宽度但仍然没有运气,我认为它可能会起作用。
  • 是的,它看起来真的是链接到文本节点的边界框而不是容器,是什么让它更奇怪。我认为目前尝试这样的解决方法是毫无意义的,唯一可行的方法是放弃变换并求助于位置:(
  • 是的,这种方法会消耗一些性能:/我认为这就是现在的答案。谢谢你:)
猜你喜欢
  • 2011-08-14
  • 1970-01-01
  • 2012-01-05
  • 1970-01-01
  • 2018-09-10
  • 2017-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多