@kevin11189, thanx for the link Kevin. I am sure there's lot of cool stuff in that repository I looked at. But I am just starting out with js step by step, small things, and I would like to accomplish that within the existing snippet. I tried several things with var maxWidth=640, but I am not able to accomplish that.
Honestly, I don't do a whole lot of js without just manipulating plugins and stuff... I can see what I can do. I have a feeling someone else is going to come in here and make me look stupid. I'm learning with you.
have you tried
if (screen.width > 640) {
$(document).ready(function() {
setHeight('.box');
});
var maxHeight = 0;
function setHeight(column) {
column = $(column);
column.each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();;
}
});
column.height(maxHeight);
}
}
or
if (document.documentElement.clientWidth > 640) {
$(document).ready(function() {
setHeight('.box');
});
var maxHeight = 0;
function setHeight(column) {
column = $(column);
column.each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();;
}
});
column.height(maxHeight);
}
}
@joshuanhibbert, awesome bro, works like a charm. Mobile first ha. I do it other way around, hmmm... I'll keep that in mind cause it makes lot of sense. Thanx.
@joshuanhibbert, Josh, I brought it with me to work and published it on server and Iam experiencing some strange behavior. When you initially open it you get equal height. When you re-size browser to 768px I get no longer equal height. When I refresh the browser at this point equal height is back. When you re-size browser back to full width I get big gap under paragraph. The script you shared with me is as I got it from jsfiddle. I might be doing something wrong with css or media query. I dodn't know. Here's the link: http://thecableconnection.com/Test/index.html
It works great on the initial load, say for a 960px grid on a big browser. However, I have a break point at 959px where everything gets narrower, and then again at 767px where all the columns stack on top of one another. The script needs to refresh at each breakpoint and readjust the column heights as they get narrower, but I'm not sure how to do that.
@joshuanhibbert, thanx Josh, just got home from work was a long day finishing online store in existing website and making it live. I am going to look at it tomorrow when I get to work and I'll get in touch with you then. Cheers.
OK, I was having issues with float clearing, it's working better for me now. How can we apply this to two different rows of columns on the same page though? I have a row of content with two columns in it like Jurotek's last example, but I also have a row in my footer that is four columns that are picking up the same height as the content row above. But each row should be independent from each other able to set a unique height. Any ideas?
@Fatbat, I'll be guessing here cause I have no knowledge of js whatsoever. If you give your boxes in footer different class name than the ones in content and add that class name to snipet, wouldn't that work?
Edit: I see you mention float clearing issue. You could easily take care of that if you set the display value of your boxes as inline-block instead float left. Here's how I did it. I gave all my boxes .b1 thru .b6 font size 1em. First I floated them left and I checked the position of second box on x axis. I wrote it down. Than I changed display to inline-block and checked the position of second box on x axis again. I took that number and subtracted from it the first measurement taken when the boxes were floated and the difference I applied as margin-right minus Xpx. Hope I make sense.
@jurotek, yes, that would probably work, but it shouldn't be necessary and it makes the script a whole lot less flexible and versatile if you need to continuously add additional classes every time you want to add a new row of equal height content. Chris Coyer had previously written a tutorial about equal height columns here, where each row is measured separately, but it doesn't really work as expected... http://css-tricks.com/equal-height-blocks-in-rows/
@Mottie took what Chris did and improved upon it and made a plugin out of it, and it works pretty good, but it wasn't at all responsive...
I'm looking for the best of both worlds. I'm sure it's doable but I suck at writing JS too. @joshuanhibbert has come up with the closest solution I've seen thus far however.
@joshuanhibbert, here's my final solution to this. Since I din't want at times boxes to be equal height like on class .b6 that stretches full width of content minus left margin or in some other situations, I set the var foo value to .equal and use that class where I want the boxes to be equal height like this.
// Wrap everything in the document ready function
$(document).ready( function() {
// Cache variables
var foo = $('.equal'),
breakpoint = 640;
// Run the following whenever the window is resized (also trigger on page load)
$(window).resize( function() {
// Remove the style attribute that is setting the height when resizing so that we can let the content dicate the height before working it out again
foo.removeAttr('style');
// Set the height variable back to 0
var height = 0;
// Set the height to that of the tallest div
foo.each( function() {
if ($(this).height() > height) {
// If an element's height is larger than what is already stored, store the new height
height = $(this).height();
}
});
if ($(window).width() >= breakpoint) {
// If the window is larger than the breakpoint width, set the height for all divs to the largest div's height
foo.height(height);
} else {
// If the window is narrower than the breakpoint, remove the style attribute that is setting the height
foo.removeAttr('style');
}
}).trigger('resize');
});
@joshuanhibbert any ideas on how to make it work with multiple independent rows without having to apply a different class to each row? BTW, the Equalizer repository moved here... https://github.com/CSS-Tricks/Equalizer
Hmm actually you just want to center the content inside of the block? Instead of modifying the demos here to act like the Equalizer plugin, you can just add this css* to the plugin (demo):
You may not like the !important flag in the css. If that's the case, you can just remove the styling from the equalizer-inner in the code at line 36. So change this:
@Mottie, the centering (either the way you described it above or using the css table/table cell method which I prefer because it's pixel perfect) works fine with the version the guys here have come up with, but it doesn't work with the Equalizer plugin because of that inner height wrapper span. The Equalizer plugin doesn't need individual CSS classes for each independent row which is really nice. There's one other issue here in that this script refreshes fine for a liquid layout, but for a fixed layout with a breakpoint, say at 959px, it doesn't recalculate the column heights and the content overflows it's container when you resize the screen smaller. When you hit the smaller breakpoint defined in the script, things stack fine and the boxes recalculate then.
So yeah, not really sure what to suggest. I could use the script here and define individual classes for each row, which is workable but isn't ideal. Or we could figure out how to get around the inner height wrapper span in the Equalizer plugin. Your thoughts?
Ok, I spent some time working on the Equalizer plugin to allow setting a breakpoint. I'll try to finish it up tomorrow after I make a nice demo and work out the bugs :)
Breakpoint @Mottie? Now I'm confused :) The only thing the Equalizer plugin doesn't allow for, the one in the CSS-Tricks repo, is vertical centering. Otherwise it's perfect. It's the one here that has issues with breakpoints.
Hi folks. I decided to reopen this thread if I may to keep all my ideas in one place what I am working on and eventually try to use to redesign existing company fixed width website to responsive one. I am hoping to accomplish that sometimes by next Spring, I hope. Maybe I rename this thread to something like "Responsive Ideas" or so.
Thanx to @joshuanhibbert, I overcome first thing and that is equal height to be used if necessary.
For the past couple of days I am working on next element (some type of responsive navigation which would give decent UX) and didn't take much vertical space. After trying several different ideas I settled on this. I moved it from fidle to Codepen. Somehow it doesn't renders correctly in editor but full screen is ok. What is your opinion on this? Is something like this used? Here's the link: http://codepen.io/jiri/full/Fhlgx
Edit: BTW, I say responsive but it's not quite. I had to limit this to 480px cause there's no way I could squeeze lot of existing content objects to 320px. But I'll be happy if I can accomplish that to 480px min.width.
@Fatbat: That demo above IS Equalizer. It still has the inner span, and all it needed were those two lines of css to vertically center the content. Or was there something I'm missing?
...it's lighter and pixel perfect (doesn't require the -em shim). However, the CSS you posted above doesn't work either. The span measures the height of the content and sets that in the style and then any vertical centering happens within that span, but I want to be vertically centering the content to the height of the column.
It's because of using the display:table to vertically center the content... which needs height set to 100%. The equalizer script doesn't expect the height of an element that it adds to be set to 100%.
The code above works great, and it looks "pixel perfect" to me.
@Mottie, I don't know why my Fiddle isn't working, but it works perfectly on my test site. I've not had any problems with the older version of Equalizer, it even equalizes divs more than one layer below the outer wrapper which is better, but of course it's not responsive :(
I got finally all my boxes equal height by using jQuery 1.8.3 and this little snipet:
With media query below I am using class full and stretching all the boxes full width of the view port like this
How do I alter that script when I go to 640px width and below not make the boxes equal height anymore? Thanks.
Check this out.... I haven't needed to use it yet, but I'm sure you can manage to make it work. I know a couple people that have.
https://github.com/paulirish/matchMedia.js/
The readme is pretty helpful too. I think this is what you're looking for.
@kevin11189, thanx for the link Kevin. I am sure there's lot of cool stuff in that repository I looked at. But I am just starting out with js step by step, small things, and I would like to accomplish that within the existing snippet. I tried several things with var maxWidth=640, but I am not able to accomplish that.
Honestly, I don't do a whole lot of js without just manipulating plugins and stuff... I can see what I can do. I have a feeling someone else is going to come in here and make me look stupid. I'm learning with you.
have you tried
or if (document.documentElement.clientWidth > 640) { $(document).ready(function() { setHeight('.box'); });
The code block broke on the second one. It starts at "if (document......."
@jurotek Is this what you are after? http://jsfiddle.net/joshnh/Mx3RX/
Note: I've taken a mobile first approach with this method. When designing responsively, I am a firm believer that mobile first is the way to go.
@joshuanhibbert, awesome bro, works like a charm. Mobile first ha. I do it other way around, hmmm... I'll keep that in mind cause it makes lot of sense. Thanx.
@jashuanhibbert Very nice. I'm saving that one for later use.
Awesome, glad it does what you want! Also, it's not hard to flip it around if you want to work the other way.
@joshuanhibbert, Josh, I brought it with me to work and published it on server and Iam experiencing some strange behavior. When you initially open it you get equal height. When you re-size browser to 768px I get no longer equal height. When I refresh the browser at this point equal height is back. When you re-size browser back to full width I get big gap under paragraph. The script you shared with me is as I got it from jsfiddle. I might be doing something wrong with css or media query. I dodn't know. Here's the link: http://thecableconnection.com/Test/index.html
@jurotek That is about the extent of my jQuery knowledge, and it doesn't take into account the changing content height. Sorry :(
It works great on the initial load, say for a 960px grid on a big browser. However, I have a break point at 959px where everything gets narrower, and then again at 767px where all the columns stack on top of one another. The script needs to refresh at each breakpoint and readjust the column heights as they get narrower, but I'm not sure how to do that.
@jurotek Out of curiosity, does this work? http://jsfiddle.net/joshnh/3cQ93/
I moved the setting of the height inside of the window resize function so that it runs it again whenever the window is resized.
@joshuanhibbert, thanx Josh, just got home from work was a long day finishing online store in existing website and making it live. I am going to look at it tomorrow when I get to work and I'll get in touch with you then. Cheers.
No worries!
@joshuanhibbert, you nailed it, got up early cause I couldn't wait to try it, thanx a bunch http://jsfiddle.net/jurotek/AwcXt/embedded/result/
OK, I was having issues with float clearing, it's working better for me now. How can we apply this to two different rows of columns on the same page though? I have a row of content with two columns in it like Jurotek's last example, but I also have a row in my footer that is four columns that are picking up the same height as the content row above. But each row should be independent from each other able to set a unique height. Any ideas?
@Fatbat, I'll be guessing here cause I have no knowledge of js whatsoever. If you give your boxes in footer different class name than the ones in content and add that class name to snipet, wouldn't that work?
Edit: I see you mention float clearing issue. You could easily take care of that if you set the display value of your boxes as inline-block instead float left. Here's how I did it. I gave all my boxes .b1 thru .b6 font size 1em. First I floated them left and I checked the position of second box on x axis. I wrote it down. Than I changed display to inline-block and checked the position of second box on x axis again. I took that number and subtracted from it the first measurement taken when the boxes were floated and the difference I applied as margin-right minus Xpx. Hope I make sense.
@jurotek, yes, that would probably work, but it shouldn't be necessary and it makes the script a whole lot less flexible and versatile if you need to continuously add additional classes every time you want to add a new row of equal height content. Chris Coyer had previously written a tutorial about equal height columns here, where each row is measured separately, but it doesn't really work as expected... http://css-tricks.com/equal-height-blocks-in-rows/
@Mottie took what Chris did and improved upon it and made a plugin out of it, and it works pretty good, but it wasn't at all responsive...
http://css-tricks.com/forums/discussion/comment/46978/#Comment_46978
I'm looking for the best of both worlds. I'm sure it's doable but I suck at writing JS too. @joshuanhibbert has come up with the closest solution I've seen thus far however.
@joshuanhibbert, here's my final solution to this. Since I din't want at times boxes to be equal height like on class .b6 that stretches full width of content minus left margin or in some other situations, I set the var foo value to .equal and use that class where I want the boxes to be equal height like this.
@jurotek Awesome! I'm glad it's working for you :)
@joshuanhibbert any ideas on how to make it work with multiple independent rows without having to apply a different class to each row? BTW, the Equalizer repository moved here... https://github.com/CSS-Tricks/Equalizer
@Fatbat There is, but I'm going to suggest asking someone that actually knows what they're talking about to answer this question. @Mottie for example!
You want to make sure you aren't repeating code, and I'm not entirely sure on the best way to handle that.
Thanks @joshuanhibbert. Understood, and thanks for the reply!
@joshuanhibbert LOL like I have a clue! :P
@Fatbat I'll look at the demo tomorrow and see what I can come up with ;)
Hmm actually you just want to center the content inside of the block? Instead of modifying the demos here to act like the Equalizer plugin, you can just add this css* to the plugin (demo):
You may not like the
!importantflag in the css. If that's the case, you can just remove the styling from theequalizer-innerin the code at line 36. So change this:to this:
* Note: the css is from Chris' article on "Centering in the Unknown"
@Mottie, the centering (either the way you described it above or using the css table/table cell method which I prefer because it's pixel perfect) works fine with the version the guys here have come up with, but it doesn't work with the Equalizer plugin because of that inner height wrapper span. The Equalizer plugin doesn't need individual CSS classes for each independent row which is really nice. There's one other issue here in that this script refreshes fine for a liquid layout, but for a fixed layout with a breakpoint, say at 959px, it doesn't recalculate the column heights and the content overflows it's container when you resize the screen smaller. When you hit the smaller breakpoint defined in the script, things stack fine and the boxes recalculate then.
So yeah, not really sure what to suggest. I could use the script here and define individual classes for each row, which is workable but isn't ideal. Or we could figure out how to get around the inner height wrapper span in the Equalizer plugin. Your thoughts?
Ok, I spent some time working on the Equalizer plugin to allow setting a breakpoint. I'll try to finish it up tomorrow after I make a nice demo and work out the bugs :)
Breakpoint @Mottie? Now I'm confused :) The only thing the Equalizer plugin doesn't allow for, the one in the CSS-Tricks repo, is vertical centering. Otherwise it's perfect. It's the one here that has issues with breakpoints.
@joshuanhibbert, @Fatbat, @Mottie,
Hi folks. I decided to reopen this thread if I may to keep all my ideas in one place what I am working on and eventually try to use to redesign existing company fixed width website to responsive one. I am hoping to accomplish that sometimes by next Spring, I hope. Maybe I rename this thread to something like "Responsive Ideas" or so.
Thanx to @joshuanhibbert, I overcome first thing and that is equal height to be used if necessary.
For the past couple of days I am working on next element (some type of responsive navigation which would give decent UX) and didn't take much vertical space. After trying several different ideas I settled on this. I moved it from fidle to Codepen. Somehow it doesn't renders correctly in editor but full screen is ok. What is your opinion on this? Is something like this used? Here's the link: http://codepen.io/jiri/full/Fhlgx
Edit: BTW, I say responsive but it's not quite. I had to limit this to 480px cause there's no way I could squeeze lot of existing content objects to 320px. But I'll be happy if I can accomplish that to 480px min.width.
@Fatbat: That demo above IS Equalizer. It still has the inner span, and all it needed were those two lines of css to vertically center the content. Or was there something I'm missing?
@Mottie: I much prefer the following for vertical centering...
...it's lighter and pixel perfect (doesn't require the -em shim). However, the CSS you posted above doesn't work either. The span measures the height of the content and sets that in the style and then any vertical centering happens within that span, but I want to be vertically centering the content to the height of the column.
@Fatbat Try this then (demo)
HTML
Script
CSS
Hey @Mottie. Sorry, got busy with other things and only just getting back to this now.
Your demo divs grows taller when the viewport is shrunk but don't get shorter when the viewport is made bigger again.
It's because of using the
display:tableto vertically center the content... which needs height set to 100%. The equalizer script doesn't expect the height of an element that it adds to be set to 100%.The code above works great, and it looks "pixel perfect" to me.
@Mottie, I don't know why my Fiddle isn't working, but it works perfectly on my test site. I've not had any problems with the older version of Equalizer, it even equalizes divs more than one layer below the outer wrapper which is better, but of course it's not responsive :(