为了账号安全,请及时绑定邮箱和手机立即绑定

具有多个属性的CSS过渡简写?

具有多个属性的CSS过渡简写?

尚方宝剑之说 2019-12-09 09:24:34
我似乎找不到具有多个属性的CSS过渡速记的正确语法。这没有做任何事情:.element {  -webkit-transition: height .5s, opacity .5s .5s;     -moz-transition: height .5s, opacity .5s .5s;      -ms-transition: height .5s, opacity .5s .5s;          transition: height .5s, opacity .5s .5s;  height: 0;  opacity: 0;  overflow: 0;}.element.show {  height: 200px;  opacity: 1;}我用javascript添加了show类。元素变得更高且可见,它只是不过渡。在最新的Chrome,FF和Safari中进行测试。我究竟做错了什么?编辑:为了清楚起见,我正在寻找简化我的CSS的简写版本。使用所有供应商前缀已经足够肿。还扩展了示例代码。
查看完整描述

3 回答

?
ibeautiful

TA贡献1993条经验 获得超5个赞

如果您有想要以同样的方式过渡几个特定的属性(因为你也有你特别一些属性并不想转型,比方说opacity),另一种选择是做这样的事情(略去了前缀):


.myclass {

    transition: all 200ms ease;

    transition-property: box-shadow, height, width, background, font-size;

}

第二个声明会覆盖其all上方的简短声明中的,并(有时)使代码更简洁。


/* prefixes omitted for brevity */

.box {

    height: 100px;

    width: 100px;

    background: red;

    box-shadow: red 0 0 5px 1px;

    transition: all 500ms ease;

    /*note: not transitioning width */

    transition-property: height, background, box-shadow;

}


.box:hover {

  height: 50px;

  width: 50px;

  box-shadow: blue 0 0 10px 3px;

  background: blue;

}

<p>Hover box for demo</p>

<div class="box"></div>


查看完整回答
反对 回复 2019-12-09
?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

通过在过渡不透明度属性时延迟0.5秒,元素在整个高度过渡期间将完全透明(因此不可见)。因此,您真正看到的唯一一件事就是不透明度发生变化。因此,您将获得与将height属性保留在过渡之外相同的效果:


“过渡:不透明度.5s .5s;”


那是你想要的吗?如果不是这样,并且您希望看到高度过渡,则在过渡的整个过程中,透明度都不能为零。


查看完整回答
反对 回复 2019-12-09
  • 3 回答
  • 0 关注
  • 676 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信