/    Sign up×
Community /Pin to ProfileBookmark

set link style on click?

I have a simple navigation to swap layer visibility with Javascript.

[CODE]<ul id=”pagenav”>
<li id=”one”><a href=”javascript://” onclick=”swapLayers(‘lyr1’); return false”>1</a></li>
<li id=”two”><a href=”javascript://” onclick=”swapLayers(‘lyr2’); return false”>2</a></li>
<li id=”three”><a href=”javascript://” onclick=”swapLayers(‘lyr3’); return false”>3</a></li>
</ul>[/CODE]

The background image of the links changes on hover. Now I’ve tried to make the background shift ‘stick’ after a link has been clicked by using [B]a:active[/B], but this doesn’t work. What should I do instead?

CSS:

[CODE]
div#pagenav1 li#one a { background-position: 0 -30px; left: 0; width: 21px }
div#pagenav1 li#one a:hover { background-position: 0 0; width: 21px }
div#pagenav1 li#one a:active { background-position: 0 0; width: 21px }
div#pagenav1 li#two a { background-position: -21px -30px; left: 21px; width: 21px }
div#pagenav1 li#two a:hover { background-position: -21px 0; width: 21px }
div#pagenav1 li#two a:active { background-position: -21px 0; width: 21px }
div#pagenav1 li#three a { background-position: -42px -30px; left: 42px; width: 21px }
div#pagenav1 li#three a:hover { background-position: -42px 0; width: 21px }
div#pagenav1 li#three a:active { background-position: -42px 0; width: 21px }[/CODE]

It would be great if someone could point me into the right direction. Is this not possible with CSS? Many thanks.

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@JickJan 07.2008 — Maybe this can help.
Copy linkTweet thisAlerts:
@spirelliauthorJan 07.2008 — Absolutely great!

One thing I've forgot about a bit:

Layer 1 (lyr1) should show at the start with navigation link 1 being highlighted at the start. Can I achieve this with CSS as well, or does this need some Javascript?
Copy linkTweet thisAlerts:
@spirelliauthorJan 07.2008 — Hmmm, on reflection I realize that clicking away from the menu item will get rid of the style. However, I need it to 'stick'. Does this mean it's gor to be Javascript?
Copy linkTweet thisAlerts:
@spirelliauthorJan 07.2008 — I think this page is the one for me:

http://bonrouge.com/br.php?page=togglit
Copy linkTweet thisAlerts:
@JickJan 07.2008 — I'm thinking, yes. JavaScript is probably the way to go for what you want. I could be wrong though. Perhaps someone else can say otherwise. But as far as I know what you're wanting would require JavaScript. But I only know about CSS. I'm a n00b still when it comes to JS. :p
×

Success!

Help @spirelli spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...