PDA

View Full Version : rollovers: css vs. javasript


Peter76
August 14th, 2008, 05:41 AM
Hello, I've just spent some time making image rollovers for my website using css. When I was about finished I found out this could be accomplished with javascript as well, with fewer lines of code ( I'm quite new to this webdesign stuff ).
Now I'm wondering: which is the better way to go here, use css or javascript?
Answers with explanations please :-)

Thanks, Peter76

Zugzwang
August 14th, 2008, 06:02 AM
IF CSS works well, use CSS. Reason: A lot of surfers deactivate JavaScript (for various reasons). Also there are browser not being able to interpret JavaScript correctly. Not to mention that JavaScript is usually more CPU-intense.

LaRoza
August 14th, 2008, 06:13 AM
Hello, I've just spent some time making image rollovers for my website using css. When I was about finished I found out this could be accomplished with javascript as well, with fewer lines of code ( I'm quite new to this webdesign stuff ).
Now I'm wondering: which is the better way to go here, use css or javascript?
Answers with explanations please :-)

Thanks, Peter76

There is no better way. There are two criteria:


Which is more reliable?
Which is easier?


Both are reliable and easy in modern browsers.

Peter76
August 15th, 2008, 04:40 PM
bump

Reiger
August 15th, 2008, 05:02 PM
Why? It's been answered like two posts before mine already?

If you want a very picky roll-over effect you're better off combining the two anyways (try mimicking the exact behaviour of your browser's drop-down menu's and you'll see why...).

If not use w/ever is more convenient.

deluser
August 15th, 2008, 08:54 PM
might I recomend the wonderfull world of JQuery (http://jquery.com/)

mssever
August 15th, 2008, 09:35 PM
Theoretically, I think it's better to use Javascript. Think of it this way: a website consists of three main concepts--structure, layout, and behavior. (X)HTML takes care of the structure, CSS is for the layout, and Javascript handles behavior. Since rollovers are behavior, it makes sense to keep the parts separate and use JS for them.

However, sometimes practicality beats purity. If, even after writing your scripts unobtrusively, you're still concerned about people who will be able to use your CSS and not your JS, then CSS might be the best option.