Animate an element's width from 0 to 100%, with it and it's wrapper being only as wide as they need to be, without a pre-set width, in CSS3 or jQuery

前端 未结 6 1169
误落风尘
误落风尘 2020-12-01 03:22

http://jsfiddle.net/nicktheandroid/tVHYg/

When hovering .wrapper, it\'s child element .contents should animate from 0px to it\

6条回答
  •  长情又很酷
    2020-12-01 04:01

    http://jsfiddle.net/tVHYg/5/

    .wrapper {
        background:#DDD;
        padding:1%;
        display:inline;
        height:20px;
    }
    
    
    span {
        width: 1%;
    }
    
    .contents {
        background:#c3c;
        overflow:hidden;
        white-space:nowrap;
        display:inline-block;
        width:0%;
    }
    
    
    
    .wrapper:hover .contents {
        -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;
    
        width:90%;
    }
    

提交回复
热议问题