- This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
Viewing 10 posts - 1 through 10 (of 10 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Does anyone have a definitive go-to for setting equal height of divs based on the container they’re in?
Been searching the web, the only thing that may work is Flexbox? Anything else out there? Particularly for a responsive designed website.
Thank you
Hey @barkins
I think flexbox is the only “real” solution in this case, although (depending on your needs), using display: table;
and display: table-cell;
could help you out as well.
What are your specific needs?
Thanks @TheDutchCoder
I went with Flexbox in the end. It seems to be working well for my design.
Awesome!
Just keep in mind its support is fairly limited: http://caniuse.com/#search=flex
But other than that, go for it! It’s the only way to push the web forward ;-)
Cheers!
Just use the function that I wrote here (jQuery):
$.fn.equalHeights = function(px) {
var currentTallest = 0;
$.each($(this), function(i, v) {
if ($(v).outerHeight() > currentTallest) {
currentTallest = $(v).outerHeight();
}
return true;
});
$.each($(this), function(i, v) {
$(v).css({
"height": currentTallest
});
return true;
});
}
Then use:
$('#container').equalHeights();
Way better than Flexbox at this point (due to its limited support).
Thanks @r00t
Awesome, will give it a shot. Does it work well in a responsive design?
Yeah, with an additional snippet of code:
$(window).on(‘resize’,function(){
$(‘#container’).equalHeights();
});
I think it would need anonresize
function to make it responsive.
There is no onresize
function.
There’s resize()
and on('resize');
, hence my previous post.
Did you notice the posting times?
I was typing mine as you typed yours however I think we both made the same point. Please forgive me for the typo.