2012-05-25 7 views
0

У меня есть родительский div, который имеет около шести div внутри. Все работает отлично, за исключением случаев, когда я добавил немного jQuery.css родительский div и дочерний div не играют правильно

Теперь родительский div не расширяется, как раньше. Я сделал родительский div relative, а дочерние divs absolute, но родительский div просто не растягивается.

JQuery

$(".child").click(function() { 
    var mypos, otherpos, $this; 

    // Move to the target element 
    $this = $(this); 
    pos = $this.offset(); 
    otherpos = $('selector_for_other_element').offset(); 
    pos.left = otherpos.left - pos.left; 
    pos.top = otherpos.top - pos.top; 
    $this.animate({ 
    left: pos.left + "px", 
    top: pos.top + "px" 
    }); 
}); 

CSS

<style type="text/css"> 
    .child{ 
    width: 250px; 
    height: auto; 
    float: left; 
    padding: 10px 5px 10px 0px; 
    background-color: #fff; 
    position: absolute 
    } 
    .parent { 
    width: 770px; 
    height: auto; 
    float: left; 
    padding: 10px 0px 0px 10px; 
    background-color: #fff; 
    position: relative; 
    overflow: none; 
    } 
</style> 

HTML

<div class="parent"> 
    <div class="child">content</div> 
    <div class="child">>content</div> 
    <div class="child">>content</div> 
    <div class="child">>content</div> 
    <div class="child">>content</div> 
    <div class="child">>content</div> 
</div> 
+0

Это именно потому, что вы сделали родительский «относительный» и «абсолютный» детей, что он не растягивается. Когда вы сделаете что-то «абсолютное», оно больше не находится в потоке документа и не влияет на другие элементы (включая родительский div). – ScottS

+0

Прежде всего, он должен быть $ (". Child"), а не $ ("child") – Ana

+0

@ Ана. .child спасибо – user618879

ответ

Смежные вопросы