- This topic is empty.
-
AuthorPosts
-
March 29, 2012 at 12:06 pm #37401
plumpnation
MemberI remember stumbling across a way to increment a value using just CSS but it’s slipped my mind.
I have a large sprite sheet, each item has three states.
When I roll over the sprite when it is being used, I want something like this.
a {
background-position: 0, 50px;
}
a:hover {
background-position: +=50px, +=0;
}
As you can see I’m trying to use the addition operator from js here to try and illustrate my point.
Does anyone have any idea how to do this without javascript….? I just can’t seem to remember and it’s driving me crazy.
I don’t mind if you can’t solve the problem but can help me with the increment problem.
P.S. This is not an “counter increment” question ;)
March 29, 2012 at 6:15 pm #100230joshuanhibbert
MemberNot currently possible unfortunately (due to poor browser support). I assume the experimental feature
calc()
is what you are referring to (https://developer.mozilla.org/en/CSS/calc)?March 29, 2012 at 6:43 pm #100234xpy
ParticipantI’m not sure what are you trying to do…
Trying to guess and playing with background-origin I did this for two states… (no ie compatibility for older than 9)…March 29, 2012 at 6:51 pm #100235Mottie
MemberThere is a css3 counter… like adding line numbers to a pre tag
pre { counter-reset: line; }
pre::line-marker { counter-increment: line; content: counter(line) "."; }But I don’t think it’ll do what you want with a three-state background image. You might need to use some javascript.
April 2, 2012 at 5:18 am #100442plumpnation
MemberOK guys thankyou so much for your help on this. I must be mistaken in thinking this was possible in CSS2. I was positive I had achieved this before without the use of javascript, but hey, if no one else knows about it, I must be wrong.
This was my first post here, and I am really impressed with the quality of the responses.
@xpy: Tried your link in Chrome and Chromium but just got a blue page. In Firefox 11, saw the site but couldn’t see the mario link. Appreciate the effort though… :)April 2, 2012 at 5:23 am #100443plumpnation
MemberAnd just to clarify WHY I wanted this functionality, it is because I auto generate the sprite sheet CSS, and then I wanted one rule to apply to all elements using this sheet.
So, every .sprite would have 50px added to it’s current y-background-position on :hover, which of course would be released on mouse out. I would not know the original background position of the sprite, merely that it needs to move 50px down from it’s current position.
Happy styling!
April 2, 2012 at 11:36 am #100456xpy
ParticipantApril 2, 2012 at 12:00 pm #100453plumpnation
MemberCheers xpy, very cool of you.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.