Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2013, 01:48 AM   PM User | #1
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Weird Vertical & Horizontal Alignment Issue...

Hello,

I have a weird issue with some vertical and horizontal alignment on my website. If you take a look at www.mixnob.com and look at the section at the bottom of the page where there are three tabs for FEATURED, ON SALE, and NEW products. There are four products across the page. Each product has a picture, and then the text below. So each of those four products should all align the same.

The problem is whenever I go to the home page, some of the images are aligned left, instead of center, and some of the images that are wider than they are tall will pull up the text below them so the ADD TO CART button is not aligned to the bottom.

But where it gets really weird is when I hit refresh on my browser, everything snaps into alignment correctly. So it seems the actual css is correct but only takes effect when the page has been refreshed. But the first time you go to the page, things are randomly out of alignment.

I have played around with the !important tag to try and force the css that is already there to take action but it sometimes doesn't seem to be working. I just want all four products to look the same. All ADD TO CART buttons should align to bottom, all images should be centered horizontally, and all images should be centered vertically as well.

Any help with this would be appreciated as I have pulled my hair out trying to get this to work correctly.

Thanks
brookfloyd is offline   Reply With Quote
Old 01-22-2013, 02:12 AM   PM User | #2
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Oh, and just to add to the description... it seems to act worst in FireFox. Safari is a little better but still exhibits the issues. And it doesn't do it every time either.

Thanks
brookfloyd is offline   Reply With Quote
Old 01-25-2013, 06:34 AM   PM User | #3
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Anyone have a chance to check this out? I have been hacking away at it and I still can't seem to figure out a solution.

Thanks,
Brook Floyd
brookfloyd is offline   Reply With Quote
Old 01-25-2013, 08:36 AM   PM User | #4
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
If you view the page in Firebug (see my sig) after it loads initially, and then again after refreshing/aligning, you can see that the .ProductImage div has had an inline style applied to it setting the height and width. This immediately suggests that there's some javascript setting (and equalising) the height.

In common.js I then find the function setProductListHeights - which is what is running and setting the height on refresh.

So, why isn't it running when the page loads initially? I can't check this, obviously, but I suspect that when the page first loads, the images have not loaded by the time that function fires, and hence it makes no changes. When the page is refreshed, the images are cached and hence the script has an effect. You could check this out by outputting some info from the function to the console.

This function is called from $(document).ready() in common.js. A possible solution would be to instead call it on $(window).load() - which won't fire until all the images have finished loading. I'd suggest having a try removing the code below from $(document).ready() (in red) and wrapping it like this:

Code:
$(window).ready(function(){
   if($('.Rating img').length > 0) {
		$('.Rating img').each(function() {
			if($(this).height() == 0) {
				$(this).load(function() {
					// Load rating img and find the tallest product.
					var imgName = $(this).attr('src').split('/');
					var imgKey = imgName.length-1;
					setProductListHeights(imgName[imgKey]);
				});
			} else {
				setProductListHeights();
				return false;
			}
		});
	} else {
		setProductListHeights();
	}
});
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Old 01-27-2013, 07:30 AM   PM User | #5
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Thanks so much for the help. I went in and did the suggested code modification but it doesn't seem to make any difference in the outcome. Unless I did something wrong, but it looks like the modified code is appearing live now with no change.

Do you have any other suggestions?

Thanks again,
Brook Floyd
brookfloyd is offline   Reply With Quote
Old 01-27-2013, 07:37 AM   PM User | #6
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Hmmm, well it appears it didn't upload the file. I will have to check with the hosting company since it is not letting me upload the common.js file successfully.
brookfloyd is offline   Reply With Quote
Old 01-27-2013, 08:26 AM   PM User | #7
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Ok, I finally got the common.js file to upload in a new location and override the old common.js file that the hosting company won't let me edit. Everything now points to the common.js file that has the modification.

I tested everything but now it results in the alignment problems and refreshing the browser doesn't change anything like it used to. Now everything stays misaligned no matter what you do in the browser.

Any additional help would be greatly appreciated. I hope I modified the code properly. I am a javascript novice. I really know very little of it. I am mostly a html/css designer.

Thanks in advance,
Brook Floyd
brookfloyd is offline   Reply With Quote
Old 01-27-2013, 09:09 AM   PM User | #8
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
I think there's an error somewhere in your amended js which is causing the whole thing to fail. However, my original code is still not solving the issue. Also, just noticed I typed $(window).ready() not $(window).load() in my code above. Oops.

This is, I think, because the $(this).load() in the script is never completing on the initial load. If I take this function out, then the script works on this test page.

The amended code is:

Code:
$(window).load(function(){
	if($('.Rating img').length > 0) {
		$('.Rating img').each(function() {
			if($(this).height() == 0) {
					var imgName = $(this).attr('src').split('/');
					var imgKey = imgName.length-1;
					setProductListHeights(imgName[imgKey]);
			} else {
				setProductListHeights();
				return false;
			}
		});
	} else {
		setProductListHeights();
	}
});
I've attached my amended js file as a text file.
Attached Files
File Type: txt common.js.txt (29.9 KB, 23 views)
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Old 01-27-2013, 09:19 PM   PM User | #9
brookfloyd
New Coder

 
Join Date: Jan 2013
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
brookfloyd is an unknown quantity at this point
Ok thanks again. I went ahead and uploaded the common.js file again with the newest revisions you made and, as you tested, everything works perfectly. So is there any issue with using it with what you took out? What was it that was taken out? I'm wondering if that will affect anything else in the site?

I did notice yesterday that it kept showing an error of syntax on line 85 (plus or minus a line) in Dreamweaver when I was originally editing it with your first suggestion. Would that maybe be the issue?

Again, thank you so much for the help. I appreciate it immensely as I have beat my head against the wall with this issue. I really need to learn some javascript. Do you know any ajax?

Thanks,
Brook Floyd
brookfloyd is offline   Reply With Quote
Old 01-28-2013, 07:39 AM   PM User | #10
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
You're welcome.

It shouldn't affect anything else as that code is solely devoted to setting the height on a row of products. I think the revised code pretty much replicates the functionality of the original code anyway.
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:00 AM.


Advertisement
Log in to turn off these ads.