Ensure two div-elements will get the same height (jquery solution)

Currently I’m working on a small web application with the requirement to bring the height of two side-by-side div elements on the same level. The content of this two elements are different and the width depends on the browser window. This means the div content floats in the elements and the height depends on the height of the inner content. I tried to find a working solution based on CSS only. At the end I want to share a jquery based solution which works well for me

  1. The following markup can be found in many web apps
    https://gist.github.com/3965331/77a38858b214ae71c2cf521fa3ee0c0048e1bca8
  2. First I added  jquery and code to identify the div with the maximum height. After that this height will be set at the second div element as well
    https://gist.github.com/3965331/1fbbfbbd2a3116ad48ed03f874695d9bfb4d7589
  3. Finally moving out the code into a separate function helps to reuse this code in other apps as well. It could als be a good idea to build a small jquery plugin
    https://gist.github.com/3965331/81308dec45be018cd4f29220460ee6f770fa5005

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s