Set a DIV height equal with of another DIV

后端 未结 7 2404
终归单人心
终归单人心 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:38

    eje211 has a point about using CSS to style your page. Here are two methods to use CSS, and one method using scripting to accomplish this:

    1. This article makes equal column heights without CSS hacks.

    2. Here is a method to get equal column heights using a CSS hack.

    3. and lastly, if you do want to use javascript/jQuery, you could use the equalize heights script that the jQuery .map() page has as a demo.

      $.fn.equalizeHeights = function(){
        return this.height( Math.max.apply(this, $(this).map(function(i,e){ return $(e).height() }).get() ) )
      }
      

      then just use it as follows:

      $('.sidebar, .content').equalizeHeights();
      

提交回复
热议问题