0

How to put equal heigts on each multiple divs?

<div class="brands"> <div class="left" style="height:50px;">different height 1 same group</div> <div class="right" style="height:50px;">different height 2 same group</div> </div> <div class="brands"> <div class="left" style="height:150px;">different height 3 same group</div> <div class="right" style="height:150px;">different height 4 same group</div> </div> 

Many thanks.

2
  • Mm don't understand the question, what has it to do with jQuery? You looking for: .brands div { height: 10px; }? Commented Apr 25, 2013 at 12:26
  • Need more information on what you are asking. Commented Apr 25, 2013 at 12:36

1 Answer 1

1

If you want them all the same:

$('div.brands').children('div').css('height', '100px'); 

Or, if different ones need different heights:

$('div.brands').eq(0).children('div').css('height', '50px'); $('div.brands').eq(1).children('div').css('height', '150px'); 

To set child divs to the height of the tallest child div in a given brands div:

var leftHeight = 0; var rightHeight = 0; $('div.brands').each(function() { leftHeight = $(this).children('div.left').height(); rightHeight = $(this).children('div.right').height(); if(leftHeight > rightHeight) { $(this).children('div.right').css('height', leftHeight + 'px'); } else { $(this).children('div.left').css('height', rightHeight + 'px'); } }); 
Sign up to request clarification or add additional context in comments.

15 Comments

But how to set height on automaticaly? style attr is for example, for group spliting, for better understanding my problem.
I'm not sure what you're asking...?
Brands divs ar multiple, for example 50 divs.
So you want to set all the divs to the height of the tallest div? Because that's what that question asks and answers, as far as I can tell
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.