Html 将 CSS3 过渡设置为无
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11848701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set a CSS3 transition to none
提问by shrewdbeans
How would I make it so a CSS transition doesn't work inside a media-query, or in any other case? For example:
我如何才能使 CSS 转换在媒体查询中或在任何其他情况下不起作用?例如:
@media (min-width: 200px) {
element {
transition: width 1s;
}
}
@media (min-width: 600px) {
element {
transition: none; // SET TO NO TRANSITION
}
}
回答by Christofer Vilander
You can set the transition-propertyto none. This way, no transition effect will be applied.
您可以将transition-property设置为none。这样,不会应用过渡效果。
Like this:
像这样:
-webkit-transition-property: none;
-moz-transition-property: none;
-o-transition-property: none;
transition-property: none;
回答by RockPaperLizard
Even better than setting transition-propertyto noneis setting transition-durationto 0s.
比将transition-property设置为none更好的是将transition-duration设置为0s。
This is the cross-browser code:
这是跨浏览器代码:
-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
-o-transition-duration: 0s;
transition-duration: 0s;
Why is this better? Because, by default, standards-compliant browsers (such as Firefox) set transition-propertyto allfor each element. They also set transition-durationto 0s. Thus, by setting transition-durationto 0s, you are most closely matching how the browser defines an element without a transition.
为什么这样更好?因为,默认情况下,符合标准的浏览器(例如 Firefox)将每个元素的transition-property设置为all。他们还将transition-duration设置为0s。因此,通过将transition-duration设置为0s,您将最接近浏览器定义没有过渡的元素的方式。
Setting the transition-durationto the default 0srenders the transition-propertyirrelevant.
将transition-duration设置为默认的0会使transition-property变得无关紧要。
回答by Andrew Dover
transition: width 0s
Should do the trick - as it's basically saying there is a transition, but 0s is too quick to see it!
应该做到这一点 - 因为它基本上是在说有一个过渡,但是 0 太快了,看不到它!