2016-01-06 72 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"); 
    });