如何申請CSS過渡到已經初始寬度設置爲auto
CSS3過渡到「n」 PX
但是如果我設置的初始寬度一定數量說50像素,過渡踢一個div 。
這裏是 - 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;
}
這是一個已知的(和預期的)行爲。你不能從/轉換到自動。 – Harry
唯一的方法是使用JavaScript。 – KittMedia