Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force all <div> elements to have same height in the page?

Tags:

html

The following picture is my product show. I use Bootstrap 3.2and the whole page is within a <div class="col-xs-12"> element and you can see the dynamically generated html code at the bottom of the image.

enter image description here

My problem is that the product-container divs don't have same heights (look at the highlighted photo).

Is it possible to fix all heights as same which doesn't affect responsiveness?

like image 276
Amin Saqi Avatar asked Sep 27 '14 09:09

Amin Saqi


People also ask

How do I keep my divs the same height?

You can use Jquery's Equal Heights Plugin to accomplish, this plugins makes all the div of exact same height as other.

How do I make div height equal to another div?

The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.

How do I make a div the same size?

With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.

How do you set height to 100% of a parent?

Answer: Set the 100% height for parents too And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.


1 Answers

A few lines of jQuery can solve this:

var maxHeight = 0;

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

$(".box").height(maxHeight);

(Replace .box with the class of the divs you want to equalize.)

Heres a quick jsfiddle to show how it works.

like image 115
johanpw Avatar answered Nov 15 '22 04:11

johanpw