You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed a more robust version of the common [equal heights](https://www.google.com/search?q=jquery+equal+heights) plugin (that everyone and their grandma has made before).
8
+
9
+
So matchHeight improves on these by adding features and handling the edge cases where the others tend to fail in practice.
10
+
11
+
### Demo
12
+
13
+
See the [jquery.matchHeight.js demo](http://brm.io/jquery-match-height-demo).
- responsive, automatically updates on window resize
21
+
- handles mixed `padding`, `margin`, `border` values (even if every element has them different)
22
+
- accounts for `box-sizing`
23
+
- handles images and other media (updates automatically after loading)
24
+
- data attributes API
25
+
- tested in IE8+, Chrome, Firefox, Chrome Android
26
+
27
+
### Status
28
+
29
+
Current version is `v0.5.0`. I've fully tested it and it works well, but if you use it make sure you test fully too.
30
+
Please report any [issues](https://github.com/liabru/jquery-match-height/issues) you find.
31
+
32
+
### Install
33
+
34
+
[jQuery](http://jquery.com/download/) is required, so include it first.
35
+
<br>Download [jquery.matchHeight.js](https://github.com/liabru/jquery-match-height/blob/master/jquery.matchHeight.js) and include the script in your HTML file:
Where `byRow` is a boolean that enables or disables row detection, default is `true`.<br>
44
+
You should apply this on the [DOM ready](http://api.jquery.com/ready/) event.
45
+
46
+
See the included [test.html](https://github.com/liabru/jquery-match-height/blob/master/test.html) for a working example.
47
+
48
+
### Data API
49
+
50
+
Use the data attribute `data-match-height="group-name"` (or `data-mh` shorthand) where `group-name` is an arbitrary string to denote which elements should be considered as a group.
51
+
52
+
All elements with the same group name will be set to the same height when the page is loaded, regardless of their position in the DOM, without any extra code required.
53
+
54
+
Note that `byRow` will be enabled when using the data API, if you don't want this then use the above method.
55
+
56
+
### Examples
57
+
58
+
$(function() {
59
+
$('.item').matchHeight();
60
+
});
61
+
62
+
Will set all elements with the class `item` to the height of the tallest.<br>
63
+
If the items are on multiple rows, the items of each row will be set to the tallest of that row.
64
+
65
+
<div data-mh="my-group">My text</div>
66
+
<div data-mh="my-group">Some other text</div>
67
+
<div data-mh="my-other-group">Even more text</div>
68
+
<div data-mh="my-other-group">The last bit of text</div>
69
+
70
+
Will set both elements in `my-group` to the same height, then both elements in `my-other-group` to be the same height respectively.
71
+
72
+
See the included [test.html](https://github.com/liabru/jquery-match-height/blob/master/test.html) for a working example.
73
+
74
+
### Advanced Usage
75
+
76
+
There are a few internal properties and functions you should know about:
77
+
78
+
$.fn.matchHeight._groups
79
+
80
+
The array that contains all element groups that have had `matchHeight` applied. Used for automatically updating on resize events.<br>
81
+
Search and modify this array if you need to remove any groups or elements, for example if you're deleting elements.
82
+
83
+
$.fn.matchHeight._update()
84
+
85
+
If you need to manually trigger an update of all currently set equal heights groups, for example if you've modified some content.
86
+
87
+
88
+
$.fn.matchHeight._apply(elements, byRow)
89
+
90
+
Use the apply function directly if you wish to avoid the automatic update functionality.
91
+
92
+
### Why not use CSS?
93
+
94
+
Making robust, responsive equal height columns for _arbitrary content_ is [difficult or impossible](http://filamentgroup.com/lab/setting_equal_heights_with_jquery/) to do with CSS alone (at least without hacks or trickery, in a backwards compatible way).
95
+
96
+
Note you should probably ensure your layout is still usable if JavaScript is disabled.
97
+
98
+
### License
99
+
100
+
jquery.matchHeight.js is licensed under [The MIT License (MIT)](http://opensource.org/licenses/MIT)
101
+
<br/>Copyright (c) 2014 Liam Brummitt
102
+
103
+
This license is also supplied with the release and source code.
104
+
<br/>As stated in the license, absolutely no warranty is provided.
0 commit comments