您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在CSS3或jQuery中,对元素的宽度进行动画处理(从0到100%),并且它的包装器仅根据需要的宽度而没有预设的宽度

在CSS3或jQuery中,对元素的宽度进行动画处理(从0到100%),并且它的包装器仅根据需要的宽度而没有预设的宽度

我想我明白了。

.wrapper {

    background:#DDD;

    display:inline-block;

    padding: 10px;

    height: 20px;

    width:auto;

}



.label {

    display: inline-block;

    width: 1em;

}



.contents, .contents .inner {

    display:inline-block;

}



.contents {

    white-space:Nowrap;

    margin-left: -1em;

    padding-left: 1em;

}



.contents .inner {

    background:#c3c;

    width:0%;

    overflow:hidden;

    -webkit-transition: width 1s ease-in-out;

    -moz-transition: width 1s ease-in-out;

    -o-transition: width 1s ease-in-out;

    transition: width 1s ease-in-out;

}







.wrapper:hover .contents .inner {



    width:100%;

}


<div class="wrapper">

    <span class="label">+</span><div class="contents">

        <div class="inner">

            These are the contents of this div

        </div>

    </div>

</div>

动画化为100%会包装,因为该框大于可用宽度(100%减去+以及其后的空白)。

相反,您可以为内部元素设置动画,该元素100%的总宽度为.contents

CSS 2022/1/1 18:23:41 有338人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶