Address: http://css-tricks.com/equal-height-blocks-in-rows/
Using jquery, there are many ways to adjust multiple columns to the same height (for example, Rob Glazebrook's method)
). The main idea is to measure the height of each column and then specify the maximum height value for each column.
However, if a block contains multiple rows and you only want to unify the height of each block in each row, what should you do? This problem may occur when a line contains thumbnails of different sizes or text blocks of different sizes.
Stephen Akins proposed a clever solution
. The main idea remains unchanged. We need to measure the height of each Div and then specify the maximum height value to each Div. But before that, you need to first view the top position of each Div to know which Div belongs to the same row and then the same height value for this row.
This is the entire process. I (author) will copy Stephen's originalCodeWe made some minor optimizations to make it more efficient.
VaR currenttallest = 0, <br/> currentrowstart = 0, <br/> rowdivs = new array (), <br/> $ El, <br/> topposition = 0; <br/> $ ('. blocks '). each (function () {<br/> $ El = $ (this); <br/> toppostion = $ el. position (). top; <br/> If (currentrowstart! = Toppostion) {<br/> // enter a new row. Set the height of all the divs in the previous row. <br/> for (currentdiv = 0; currentdiv <rowdivs. length; currentdiv ++) {<br/> rowdivs [currentdiv]. height (currenttallest); <br/>}</P> <p> // reset the parameter value for the new row <br/> rowdivs. length = 0; // empty the array <br/> currentrowstart = toppostion; <br/> currenttallest = $ el. height (); <br/> rowdivs. push ($ El); <br/>}else {<br/> // Add the next DIV in the same row to the list, and check whether it is higher than the current maximum value <br/> rowdivs. push ($ El); <br/> current Tallest = (currenttallest <$ El. Height ())? ($ El. height (): (currenttallest); <br/>}< br/> // set the uniform height for the DIV in the last row <br/> for (currentdiv = 0; currentdiv <rowdivs. length; currentdiv ++) {<br/> rowdivs [currentdiv]. height (currenttallest); <br/>}< br/> });
$ ('. Blocks') can be replaced with any CSS Selector Used to represent elements of the same height.
To process the dynamic width, You can encapsulate the above code into a function. When you adjust the window size, you can call it.
$ (Window). Resize (function () {<br/> equalizethosemofos (); <br/>}