Wednesday, January 30, 2008
CSS Question: Dynamic parameters?
Wednesday, January 30, 2008
I am coding up a client's logo page in CSS for HTML delivery right now, and I have rollovers working on the images without using javascript... which was the goal.
Here is an example image file:

You see that it has both states for it in the image... faded and full-color rolled. The rollover is achieved with some CSS:
Now, what if you want to display a bunch of different logos in the same manner... that leads to a whole lot of CSS... two chunks for EACH logo on a page.
Is there some kind of way to supply CSS with a parameter... the only thing changing in the CSS above would be the image path really. Javascript would be okay I suppose, but the solution would need to work in FF, Safari and IE7.
Any ideas? I can't use PHP, but can use SHTML or ASP.
Here is an example image file:

You see that it has both states for it in the image... faded and full-color rolled. The rollover is achieved with some CSS:
a.kronosNow here is the snippet of HTML that displays the logo itself:
{
display: block;
cursor: default;
width: 112px;
height: 87px;
background: url("client_logos/logo.gif") 0 0 no-repeat;
background-color: #FFF;
text-decoration: none;
float: left;
}
a:hover.kronos
{
background-position: -112px 0;
}
<a class="kronos" href="#"> </a>Now thats cool enough, the image is shifted 1/2 of its width when rolled over. Giving you a rollover effect.
Now, what if you want to display a bunch of different logos in the same manner... that leads to a whole lot of CSS... two chunks for EACH logo on a page.
Is there some kind of way to supply CSS with a parameter... the only thing changing in the CSS above would be the image path really. Javascript would be okay I suppose, but the solution would need to work in FF, Safari and IE7.
Any ideas? I can't use PHP, but can use SHTML or ASP.
Comments:
There are currently 6 Comments:
-
Jim said...“Google "CSS sprites" - there are a few web based 'generators' out there where you can upload you images - define some parameters and it will spit out your CSS.
For something more fancy you can check out something like the 'cycle' jQuery plugin.”



