PLEASE SEE CODEPEN FOR CLARITY: http://codepen.io/geochanto/pen/LGNWML
var maxHeight = 0;
$('li a').each(function() {
maxHeight = maxHeight > $(this).outerHeight() ? maxHeight : $(this).outerHeight();
var linkHeight = $(this).outerHeight();
var halfLinkHeight = parseInt(linkHeight / -2);
$(this). css({
'margin-top' : halfLinkHeight,
'height' : maxHeight
});
});
$("li").css("height", maxHeight);
So I have this code that calculates height of links, then makes them all the height of the tallest one, and adds some negative margin on top for purposes of vertically middle-aligning them all inside their respective parents. Everything works as I want, except, I've been trying to get this height to recalculate and apply to <li>
and <a>
on window resize with various methods but none worked.
I've tried these, but perhaps my syntax was wrong, idk: