Set a DIV height equal with of another DIV

后端 未结 7 2431
终归单人心
终归单人心 2020-12-08 11:06

I have two DIVs, .sidebar and .content and I want to set .sidebar to keep the same height with the .content.

I\'ve tried the f

7条回答
  •  被撕碎了的回忆
    2020-12-08 11:30

    Works like a charm:

    function sidebarHandler() {
      jQuery(".sidebar").css({'height':(jQuery(".content").height()+'px')});
      jQuery(".sidebar").height(jQuery(".content").height());
      var highestCol = Math.max(jQuery('.sidebar').height(),jQuery('.content').height());
      jQuery('.sidebar').height(highestCol);
    }
    

    initialize it with all your other jQuery stuff:

    jQuery(document).ready(function() { 
      sidebarHandler();
    });
    

提交回复
热议问题