css3从宽度自动转换为"n".像素 [英] css3 transition from width auto to "n" px
本文介绍了css3从宽度自动转换为"n".像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将CSS过渡应用于初始宽度设置为auto
how do I apply css transition to a div which has initial width set as auto
但是,如果我将初始宽度设置为某个数字(例如50像素),过渡就会开始.
However if I set the initial width to some number say 50px, the transition kicks in.
这是-演示
.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;
}
推荐答案
默认情况下min-width
将包含在元素width
by default min-width
will take inside element width
.container {
width: 200px;
background: red;
height: 50px;
}
.child1 {
background: black;
display: inline-block;
}
.child2 {
background: blue;
display: inline-block;
width: auto;
min-width: 0px; /*changed width to min-width */
float: right;
-webkit-transition: 2s;
transition: 2s;
}
.child2:hover {
min-width: 100px; /* changed from width to min-width */
}
<div class="container">
<div class="child1">
child1
</div>
<div class="child2">
child2
</div>
</div>
这篇关于css3从宽度自动转换为"n".像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文