Vertical space on elements with position:absolute

前端 未结 3 733
名媛妹妹
名媛妹妹 2021-02-19 02:43

How can I make elements with position:absolute and dynamic height occupy vertical space using only css? Is there any trick with containers and disp

3条回答
  •  忘掉有多难
    2021-02-19 02:59

    position: absolute means they don't occupy space in the flow. However, you don't have to animate using margin, you can use float to let the elements take up whatever space, and make each of the elements position:relative.

    div.animate-me {
       width: 300px;
       margin: 20px;
       float: left;
       left: -1000px; // Make them start offscreen
       position: relative;
       border: 1px solid red;
       visibility: hidden
    }​
    
    $('div').css().animate({
        left: 0
    });
    

    SAMPLE http://jsfiddle.net/qxzzX/1/

提交回复
热议问题