views:

175

answers:

3

Could anyone help me with this problem? Code zip is here: (link taken down)

I have made everything valid but Chrome still calculates the height of the elements completely wrong (9 in every 10 times...)...


Well, technically it does.

$(document).ready(function() {
            function resizeIt() {
                var extDiv = $('#externalWrapper').height();
                var wrapper1 = $('#wrapper1').height();
                var wrapper2 = $('#wrapper2').height();
                var wrapper3 = $('#wrapper3').height();

                $('#wrapper1-mid').css({'height':extDiv - ($('#wrapper1-top').height()+$('#wrapper1-bottom').height())-4});
                $('#wrapper2').css({'marginTop':extDiv-wrapper2});
                $('#wrapper3-mid').css({'height':extDiv -($('#wrapper3-top').height()+$('#wrapper3-bottom').height())+1});

                if($('ul#related-linklist > li').size() > 15) {
                    $('#spacer').attr({'height':(wrapper2-250)});
                    $('#product-image').css({
                        'marginTop':0,
                        'marginLeft':0
                    });
                }
            }
            resizeIt();
        });

So that's my code, in Chrome it doesn't resize the margins/heights correctly at all. But works fine in Safari..

IE/Firefox are unaffected.

+2  A: 

Update: You are correct about, not needing to add 'px' to the end of the values. But I've updated the code below to use window.load as I think that might be the problem.

When using css you should include the px at the end. Also, you have a height attribute which should be css (this is untested):

$(window).load(function() {
        function resizeIt() {
            var extDiv = $('#externalWrapper').height();
            var wrapper1 = $('#wrapper1').height();
            var wrapper2 = $('#wrapper2').height();
            var wrapper3 = $('#wrapper3').height();

            $('#wrapper1-mid').css({'height':extDiv - ($('#wrapper1-top').height()+$('#wrapper1-bottom').height())-4 + 'px' });
            $('#wrapper2').css({'marginTop':extDiv-wrapper2 + 'px' });
            $('#wrapper3-mid').css({'height':extDiv -($('#wrapper3-top').height()+$('#wrapper3-bottom').height())+1 + 'px' });

            if($('ul#related-linklist > li').size() > 15) {
                $('#spacer').css({'height':(wrapper2-250) + 'px' });
                $('#product-image').css({
                    'marginTop':0,
                    'marginLeft':0
                });
            }
        }
        resizeIt();
    });
fudgey
Hey thanks for you code, still no change I'm afraid - also, I was under the impression that the 'px' is not really needed?
Neurofluxation
jQuery will add the 'px' for you if you omit it
Richard M
px (or other unit) is needed in CSS unless the value is zero. The reason the px is needed is because there are several other possible units, and neither CSS nor JQuery can be certain which you mean.
Spudley
I understand your contract concerns, but could you post a demo on jsFiddle?
fudgey
@fudgey - that's kind of like saying "I know you can't rob a bank, but could you rob a post office?" - afraid not my old chum... I'll see what I can do
Neurofluxation
I've managed to get the files together for a "gander" if you dont mind downloading them - i know it's frowned upon, but I'm tearing my hair out!
Neurofluxation
Well after looking at the files, I think the problem is occurring because the images aren't loaded. Try switching the `document.ready` to `window.load`. And you are correct about not needing to add 'px' to the end.
fudgey
@Fudgey - Excellent! This has been annoying me for a little while now, never realised it had to be in a `window.load` instead :) Thanks! well deserved rep for you!
Neurofluxation
A: 

The HTML in your jsFiddle link is a bit of a mess, which may be the root of your problem.

You have several unclosed <img> elements, an extra <html> at the top, and several elements sharing the same id. You also have a <div> nested inside a <span>, which isn't valid.

http://infohound.net/tidy/ is a useful tool for validating & cleaning up HTML.

RickF
Yeah I know, I've tidied that up - I said that JSFiddle just won't work because I can't release all of the HTML (and I've sorted out the self-closing tags now as well)
Neurofluxation
Without a example that demonstrates the problem, it's difficult to actually diagnose it. It doesn't need to be the full page, but a sample subset which still shows the problem is necessary.
RickF
I've added as much HTML as I can without compromising the clients confidentiality...
Neurofluxation
Without CSS, or even a description of the desired behavior, it's hard to tell what you *want* to happen. When I use the code you've provided, it is resizing the divs and margins. It may not be doing what you mean, but I can't divine what that is.
RickF
@rickF - updated question to include a download of my files - all images and names have been censored
Neurofluxation
A: 

I've noticed that in Chrome sometimes things are positioned a bit off, and it's most likely because of the WebKit rendering engine. What I've done to counter this in the past is to just sniff Chrome and add a custom class to any affected objects ('chrome' or 'webkit' or something) and then write code specific to those objects.

This idea admittedly sucks, but it is a plausible workaround/hack if you need this working NOW.

Jason