WordPress / Web Development Tutorials
(Best WordPress Tutorials)

CSSHTMLJavaScriptjQueryMySQLPHPSilvaTechnologiesWooCommerceWordpress
Silva Web Designs - Blog

How to Create Equal Height Elements / Columns

In this simple tutorial, we’re going to show you how you can set all elements with a particular class to the highest element height. To do this, we need to loop through all elements with a particular class, get the highest value, then match all other elements to the same height. We can do this using jQuery as follows:


var maxHeight = 0;

$(".some-element").each(function(){
   if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
});

$(".some-element").height(maxHeight);

Awesome, we now have set all elements to the same height. We can take this one step further as elements can change in max height when you are shrinking the browser width for example. What we can do here is use the resize function to update the values.

To make things easier, we can create a function, then call the function both on page load and within the resize function as follows:


var maxHeight = 0;

function matchMaxHeight() {
	$(".some-element").each(function(){
	   if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
	});

	$(".some-element").height(maxHeight);
}

matchMaxHeight();

$(window).resize(function() {
	matchMaxHeight();
});

Pretty straightforward right?

If this tutorial as helped you or if you need some further explanation on the above code, feel free to drop us a comment below and we’d love to assist you.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital-related. His main expertise is with WordPress and various other CMS frameworks. If you need responsive design, SEO, speed optimisation or anything else in the world of digital, you can contact Silva Web Designs here; [email protected]

It’s good to share

Join the discussion

Related Posts

Related - Full Width Containers in Limited Width Parents

CSS / 13th March 2025

Full Width Containers in Limited Width Parents

Read More Related - How to make Responsive Slanted Divs in CSS – 2020 Version

CSS / 30th September 2020

How to make Responsive Slanted Divs in CSS – 2020 Version

Read More