【发布时间】:2016-03-22 08:39:12
【问题描述】:
如何将 css 过渡应用到初始宽度设置为 auto 的 div
但是,如果我将初始宽度设置为某个数字(例如 50 像素),就会开始过渡。
这里是-DEMO
.container {
width: 200px;
background: red;
height: 50px;
}
.child1 {
background: black;
display: inline-block;
}
.child2 {
background: blue;
display: inline-block;
width: auto; /* this does not work */
/* width: 50px; */ /* this works */
float: right;
-webkit-transition: width 2s;
transition: width 2s;
}
.child2:hover {
width: 100px;
}
【问题讨论】:
-
这是一个已知(和预期)的行为。您不能从/到自动转换。
-
唯一的办法就是使用 JavaScript。
标签: css css-transitions