Forum Moderators: not2easy

Message Too Old, No Replies

Clever CSS Trick

Just had to share

         

aaronjf

8:05 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



I just thought of something clever I thought I would share with the rest of you. Not to toot my own horn, but to share a trick I think others can benefit from.

Problem: One shopping cart system that manages several domains. The system recognizes which domain the query is coming form and applies the appropriate CSS file like a skin. Each domain has a logo that has the same dimensions in the upper right left hand corner of the page. Since the logo needs to change through the CSS as a background image to correspond the the domain the user is in, how do you make it so that the users can still click on the logo and go back to the home page?

Answer: Create a transparent GIF matching the domains' logos’ dimensions. Next insert it in the space where the logo will appear through the CSS. Then link the transparent GIF with a general home link = /index. Now the logos can be changed out through the CSS, but you give the user the impression that they are clicking on the logo to return to the home page. In actuality they are clicking on the transparent gif which they see through too the logo!

Hope others find this useful

SuzyUK

9:41 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for that aaronjf

more food for thought....

why use a transparent gif.. when the <a> element with display: block; with the dimensions of the logo (set via CSS) will do the same ;)

Suzy

urthshu

5:57 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



Hello, just joined and read this.

I think it's a very nice idea- but there is a question bugging me: The whole cross-browser thing... might be a little tricky getting that logo/gif/transparent area to show up right where you need it.

Nonetheless....hmmm!

aaronjf

6:45 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



The trasperent GIF. I guess you come at it which ever way you are most comfortable, coding or WYSIWIG. The gif works better for people that only use WYSIWYG. When I started a couple of years ago, I first learned through WYSIWYG. So I guess I still come at more proplems from that angle still. There is however, one added bonus to using the GIF from an SEO stand point - ALT Text. Especially in the instance of it being the first image on the page. But, the use of the A tag would be good too - just limited functionality.

As for cross browser. If your CSS is solid, cross browser position of the GIF should not be a problem. So far I have been checking the CSS I am working on that used the above mentions trick on a Mac w/OS X w/Safari, Mac w/OS 9 w/Explorer, PC w/XP w/explorer, PC w/98 w/Explorer and they are all displaying exactly the same. In particular, I never experianced a problem with the GIF not showing up in the right place.

A practice I have adopted for cross browser checking is to set a refresh tag in a test page. The set up a couple of machines near the one you are working on and pull up the test page in each one. That way you can see what is happening cross browser/platform while you are working.

Shadows Papa

3:32 am on Jan 31, 2004 (gmt 0)

10+ Year Member



>>So far I have been checking the CSS I am working on that used the above mentions trick on a Mac w/OS X w/Safari, Mac w/OS 9 w/Explorer, PC w/XP w/explorer, PC w/98 w/Explorer and they are all displaying exactly the same. In particular, I never experianced a problem with the GIF not showing up in the right place.
<<

Uh, that's not what I consider "cross-browser". I'd consider Firebird/Mozilla/Netscape, IE, Opera, etc. to be cross-browser testing. Other than the Mac, you still appear to be limiting it to IE.

It's a great trick, but I'd suggest testing with a few more browsers and OS's, Linux, Unix, for example. A growing number are using "alternative OS's" (and for good reason, IMHO)

Shadows Papa

Oaf357

4:58 am on Jan 31, 2004 (gmt 0)

10+ Year Member



That's a great tip but I have to agree the cross browser compatibility issues you would have could be an utter nightmare.

SuzyUK

11:00 am on Jan 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Those of you that are mentioning "cross browser compatibility" issues... what are they?

It was very kind of aaronjf to share this idea/tip so if there are problems rather than just speculating and subsequent writing off of the idea wouldn't some testing and constructive feedback be nice..

I already use this trick... (before the post) and if there are any "issues", I'm still unaware of them but would like to know because AFAIK there are no cross browser issues here it's just plain simple CSS positioning

Suzy

aaronjf

3:30 pm on Feb 12, 2004 (gmt 0)

10+ Year Member



Yes, It does check out in Mozilla and Opera. I personally never check Netscape, but that is mainly because I can only see 1% of users using it and you can't please all the people all the time.

I am now using this method to control all of the general graphics in the system and as of yet have not found an instance where the transperent GIF and Background graphic do not appear inline with each other... as long as you are carefull with your work.

Thanks SuzyUK

PatrickDeese

3:41 pm on Feb 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I used this method on a couple of content sites, where I applied a generic CSS template to format the basic HTML code and found that it did not work as expected all the time, especially if your links have a background color on hover.

The main problems seemed to be Mozilla for Linux, and since a lot of the pages were technical in nature, I have a higher than usual percentage of linux browsers.

However, as one of my design assistants pointed out - people on Linux are used to seeing broken pages. ;)

mep00

10:53 pm on Feb 12, 2004 (gmt 0)

10+ Year Member



I guess you come at it which ever way you are most comfortable, coding or WYSIWIG.
Maybe that's why I don't think it's such a good idea. I'll admit it's cute, and on that level I like it, but it just seems overly complicated and too prone to problems. What happens if the user has css diabled? How will they even know to click there? Or what happens when images are off? With server side scripting it's easy to check what the url is and make changes accordingly.

It all goes back to my feeling of never trust the user agent to anything right if you don't have to. They have a hard enough time displaying plain HTML, and now you want to add tricks?

aaronjf

12:37 am on Feb 13, 2004 (gmt 0)

10+ Year Member



As far as the image not showing up, if you are using proper XHTML markup you should be filling every image's ALT text. If it where a cart button you would say "ADD TO CART" etc.

As for it being to complicated. The other option would have been to program the CMS to recognize the domain and apply the right graphics along with the right CSS file. If you are already working with a system that could benifit from this trick and you are reasonably accompished with CSS, I don't see how this would be very complicated relative to everything else you would have to know how to do. The CSS involved in pulling this off is not that complicated.

No one way of doing things is ever full proof 100% of the time when building Web Sites. There is always going to be that user that has this turned off, this turned on, an outdated browser, an outdated computer, an outdated connection speed, and the list goes on. Unless you are just dumping text into the page with no regard for layout, images, or any other content, that being the only exception to getting 100%. Even then I am not totally convinced you would reach 100%. At best most of us cross our fingers and hope that it reaches 97% - 99% of the users.

I found something that has become very useful and very flexible for my purposes on an Ecom site network of 8 sites. So far the solution seems to be holding up and not presenting problems for me. If what I have shared does not work for you don't use it. I posted this for other people that might have a similar problem that could benifit from all the thought I have given the particular problem I ran into. I did not post this to spend all day validating it and answering every single what if the guy is driving 35 miles an hour in a brown 70s Ford Pinto with bald tires, an AM 8 track radio, and tinfoil on his head in the year 2010.