2016-01-06 71 views
1

我有一個常規菜單,其中2個下拉菜單使用position:absolute;製作下拉菜單(絕對位置)增加父母高度

我想實現的是這些子菜單增加了父元素的高度。 就像下面的圖片: enter image description here 有人知道一種方法來做到這一點?如果可能的話只使用CSS?

在此先感謝

+1

你可以使用JavaScript的這一點,但它會很高興看到你的代碼,所以我們可以真正嘗試修復它。做一個https://jsfiddle.net/ –

+0

重複 - http://stackoverflow.com/questions/12070759/make-absolute-positioned-div-expand-parent-div-height?rq=1 –

回答

1
$(function(){ 

    $("ul.menubar").mouseover(function(){ 

     $(this).mousemove(function(){ 

      var bigger=0; 
      var offset=0; 

      $(this).find(" li ul li:last-child:visible").each(function(i,elem) { 
       offset = $(elem).offset().top + $(elem).height() - 120; 
       if(offset>bigger)bigger=offset; 
      }); 

      $('#div_menu').height(bigger); 

     }); 

    }).mouseout(function() { 

     $('#div_menu').css('height','auto'); 

    }); 

}); 
0

使用jQuery嘗試:

$("#divIdNeeded").on("mouseover", function() { 
     $("#parentDivId").css("height", "400px"); 
    });