|
| Index | Recent Threads | Unanswered Threads | Who's Online | User List | Help |
|
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 10
|
|
| Author |
|
|
Advanced Member Joined: Jun 14, 2003 Post Count: 2940 Status: Offline |
Hi, Using the latest version of FF, I've come across what I believe is a bug-related-problem that only occurs when in standards compliant mode - that is to say, when in quirks mode, the DOM script works fine. So if I have this doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> The script works in FF and IE6. On the flip side, if I have this doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> or <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> The script does not work in FF, but it does continue to work in IE6. The scripts purpose is to even out <div> heights - a common problem with CSS layouts. THE SCRIPT: matchHeight=function(){ var divs,contDivs,maxHeight,divHeight,d; divs=document.getElementsByTagName('div'); contDivs=[]; maxHeight=0; for(var i=0;i<divs.length;i++){ if(/\bcontainer\b/.test(divs.className)){ d=divs; contDivs[contDivs.length]=d; if(d.offsetHeight){ divHeight=d.offsetHeight; } else if(d.style.pixelHeight){ divHeight=d.style.pixelHeight; } maxHeight=Math.max(maxHeight,divHeight); } } for(var i=0;i<contDivs.length;i++){ contDivs.style.height=maxHeight; } } window.onload=function(){ if(document.getElementsByTagName){ matchHeight(); } } ---------------------------------------- Stefan Mischook Video Tutorial Store | Web Templates ---------------------------------------- [Edit 8 times, last edit by admin at Mar 30, 2006 8:54:53 AM] |
||
|
|
Advanced Member Joined: Jun 14, 2003 Post Count: 2940 Status: Offline |
CONTINUED FROM ABOVE: My markup contains two <div>'s that are tagged with the class of 'container': <div id="centerDoc" class="container"> ... </div> <div class="mainmenu" class="container"> ...</div> ... </div> The script iterates through the DOM and collects references of any <div> with the class of container and then does a little math to match their heights evening out the <div>s heights. Anyway, the script simply does not work in FF when I use a proper doctype .. any ideas what could be wrong? ![]() ... Problem solved. Needid to change this line: contDivs.style.height=maxHeight; to contDivs.style.height=maxHeight + "px"; WHY? I got this reminder from a guy at mozilla: "in standards compliace mode Firefox needs the unit, because not having a unit doesn't comply to the standards you see (is that maxheight em's, pixels, points?) IE of course just does whatever it feels like, as usual." - Ah, good old IE ... just like an overly forgiving mother covering up and making excuses for your mistakes! ;) Would you guys be interested in a little video on how to use this script? Thanks, Stef ---------------------------------------- Stefan Mischook Video Tutorial Store | Web Templates ---------------------------------------- [Edit 4 times, last edit by admin at Mar 30, 2006 9:02:19 AM] |
||
|
|
Advanced Member USA Joined: Mar 24, 2005 Post Count: 3000 Status: Offline |
Were you able to test this in IE7b2 before adding the measurement unit, px? If so, did it work in IE7? 2nd Q: When would you need this? I remember a post of yours from mid 2005 related to this subject... But, don't recall in what situation a js script is the only or preferred solution for the css problem you reported. ---------------------------------------- "The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo Save the developers<!> Maine Webworks |
||
|
|
Advanced Member UK Joined: Dec 29, 2004 Post Count: 1662 Status: Offline |
The script sets all columns to the height of the largest column. We all know that it is virtually impossible to really have DIVs the same height, without putting in fixed height values (which isn't good for people who set large default font sizes). ---------------------------------------- Pavonis Mons | Listen of the week: "Residue of Desire" by Acumen |
||
|
|
Advanced Member Joined: Jun 14, 2003 Post Count: 2940 Status: Offline |
"Were you able to test this in IE7b2 before adding the measurement unit, px? If so, did it work in IE7?" I havent' test in IE 7. Matching <div> heights is a pain in the butt and this little script solves the problem without having to hack around with CSS tricks ... Do you guys want a video on applying this or is it clear enough? Stef ---------------------------------------- Stefan Mischook Video Tutorial Store | Web Templates |
||
|
|
Advanced Member Joined: Sep 3, 2005 Post Count: 2206 Status: Offline |
Well I thought I'd try this on an existing layout so I pasted the code between script tags into the head of an existing page that has columns, added a container class to each of them and.... do I need to add something, change a variable to get it to work? ---------------------------------------- Quiquid latine dictum sit altum viditur |
||
|
|
Advanced Member UK Joined: Dec 29, 2004 Post Count: 1662 Status: Offline |
window.onload=function() This seems a bit strange. Shouldn't you put onload="matchHeight()" in the body tag? And functions should be defined like this: function name() { ..... } ---------------------------------------- Pavonis Mons | Listen of the week: "Residue of Desire" by Acumen |
||
|
|
Advanced Member Joined: Jun 14, 2003 Post Count: 2940 Status: Offline |
That is what you call an 'anonymous' function. The advantage of anonymous functions is that it allows you to easily access variables within its' parent function. It is like Java's anonymous inner class - if that helps at all? ---------------------------------------- Stefan Mischook Video Tutorial Store | Web Templates |
||
|
|
Stranger Joined: Jul 26, 2006 Post Count: 1 Status: Offline |
Well I thought I'd try this on an existing layout so I pasted the code between script tags into the head of an existing page that has columns, added a container class to each of them and.... do I need to add something, change a variable to get it to work? This script seems to be incomplete and broken. i've recoded it to work. how's about this... I also put in a parameter to the matchHeight function so you can say which bunch of divs you want to make the same height. For example... and you'd run it by calling matchHeight('group1') (this relies on the happy fact that you can give a div more than one class). |
||
|
|
Advanced Member Joined: Sep 3, 2005 Post Count: 2206 Status: Offline |
I'm glad you dug this up, I realize now why Stef's script wasn't working (yours won't work either as posted, and I ran into the same problem when trying to post a javascript code). Notice how both are italicized? The forum uses BBcode and in BBcode [ i ] means italics. Since the script contains [ i ] it got eaten and rendered the rest in italics. Source files containing the full code that works can be downloaded from the article and tutorial The Matching Columns Script: Matching CSS div Heights I also put in a parameter to the matchHeight function so you can say which bunch of divs you want to make the same height. The orginal code already has the ability of specifying which divs you want equal height by adding the class"column". ---------------------------------------- Quiquid latine dictum sit altum viditur ---------------------------------------- [Edit 2 times, last edit by billyboy at Jul 27, 2006 7:16:25 AM] |
||
|
|
|
|
|
Current timezone is GMT May 23, 2013 3:46:42 AM |