禁用/关闭继承的 CSS3 过渡
因此,我将以下 CSS 过渡附加到元素:
a {
-webkit-transition:color 0.1s ease-in, background-color 0.1s ease-in ;
-moz-transition:color 0.1s ease-in, background-color 0.1s ease-in;
-o-transition:color 0.1s ease-in, background-color 0.1s ease-in;
transition:color 0.1s ease-in, background-color 0.1s ease-in;
}
有没有办法在特定元素上禁用这些继承的过渡?
a.tags { transition: none; }
似乎没有做好这项工作。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
transition: none(对 Opera 进行了特定调整)
考虑到以下 HTML: ...和 CSS:
/nW2Wt/" rel="noreferrer">JS Fiddle 演示。
在 Ubuntu 11.04 上使用 Chromium 12、Opera 11.x 和 Firefox 5 进行了测试。
对 Opera 的具体修改是使用
-o-transition: color 0 escape-in;
,它的目标与其他transition
规则中指定的属性相同,但设置转换时间为0
,这有效地防止了转换变得明显。使用a.noTransition
选择器只是为没有转换的元素提供一个特定的选择器。编辑注意@Frédéric Hamidi的回答< /a>,使用
all
(至少对于 Opera 来说)比列出您不想要的每个单独的属性名称要简洁得多进行过渡。更新了 JS Fiddle 演示,展示了 Opera 中
all
的使用:-o-转换:全部 0 无
,在自删除 @Frédéric 的答案。The use of
transition: none
seems to be supported (with a specific adjustment for Opera) given the following HTML:...and CSS:
JS Fiddle demo.
Tested with Chromium 12, Opera 11.x and Firefox 5 on Ubuntu 11.04.
The specific adaptation to Opera is the use of
-o-transition: color 0 ease-in;
which targets the same property as specified in the othertransition
rules, but sets the transition time to0
, which effectively prevents the transition from being noticeable. The use of thea.noTransition
selector is simply to provide a specific selector for the elements without transitions.Edited to note that @Frédéric Hamidi's answer, using
all
(for Opera, at least) is far more concise than listing out each individual property-name that you don't want to have transition.Updated JS Fiddle demo, showing the use of
all
in Opera:-o-transition: all 0 none
, following self-deletion of @Frédéric's answer.如果您想禁用单个过渡属性,您可以执行以下操作:(
因为零秒过渡与无过渡相同。)
If you want to disable a single transition property, you can do:
(since a zero second transition is the same as no transition.)
删除所有过渡的另一种方法是使用
unset
关键字:与
transition
属性,unset
相当于initial
,因为transition
不是继承属性:了解
unset< 的读者/code> 和
初始
可以立即判断这些解决方案是正确的,而无需考虑transition
的具体语法。Another way to remove all transitions is with the
unset
keyword:When used with the
transition
property,unset
is equivalent toinitial
, sincetransition
is not an inherited property:A reader who knows about
unset
andinitial
can tell that these solutions are correct immediately, without having to think about the specific syntax oftransition
.此外,还可以通过设置属性
transition-property: width, height;
来设置将要转换的属性列表,更多详细信息此处Additionally there is a possibility to set a list of properties that will get transitioned by setting the property
transition-property: width, height;
, more details here您还可以取消继承包含元素内的所有转换:
CSS:
HTML:
You could also disinherit all transitions inside a containing element:
CSS:
HTML:
基于 W3schools,默认转换值为:
all 0s escape 0s
,这应该是禁用转换的跨浏览器兼容方式。这是一个链接:https://www.w3schools.com/cssref/css3_pr_transition.asp
Based on W3schools default transition value is:
all 0s ease 0s
, which should be the cross-browser compatible way of disabling the transition.Here is a link: https://www.w3schools.com/cssref/css3_pr_transition.asp