/    Sign up×
Community /Pin to ProfileBookmark

Link Activating a CSS file

First of all, I’m fairly new, just so you know.

I need to make a link activate a css file AND go to a different page. Basically, like this:

[CODE]<a href=”page.html” onclick=”Have the HTML file’s css be cssstyle1.css, how do I do this?”> Black Backround – White Text</a>[/CODE]

to post a comment
CSS

9 Comments(s)

Copy linkTweet thisAlerts:
@KDLANov 06.2006 — http://alistapart.com/stories/alternate/

This shows you how to implement alternate stylesheets.

KDLA
Copy linkTweet thisAlerts:
@doggydoodooauthorNov 06.2006 — That's exactly what I want, but that's old and doesn't work. If it's not old, then it just doesn't work. It goes to paul.css, but literally shows paul.css, not in a webpage.
Copy linkTweet thisAlerts:
@KDLANov 06.2006 — You didn't read it carefully. You have to link to, or include, a javascript file in the <head> section. Then name the page's "regular" styles "default" in your CSS linkage (also in the <head> section); then provide links to the alternate ones, naming them whatever you want. After that, you apply some javascript to the link in the <body> section, which calls the preferred stylesheet. When the link is clicked, the stylesheet will be applied to the page currently in the window. However, you have to have the same IDs and classes among all stylesheets.
Copy linkTweet thisAlerts:
@doggydoodooauthorNov 08.2006 — I told you I'm not experienced. I would be really grateful if you just sent me the code for a link to change the preffered css to cssone.css. I don't even need the link to a different website. Please-[I]someone[/I]-do this for me.
Copy linkTweet thisAlerts:
@doggydoodooauthorNov 08.2006 — I'm not trying to be rude. Just [I]please[/I] because this is going to be used on an actual website - [URL]http://thestuff.atspace.com/[/URL]
Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 08.2006 — We aren't here to just do things for you. You haven't showed any effort that you are actually trying.
Copy linkTweet thisAlerts:
@CentauriNov 08.2006 — The article KDLA linked IS quite a simple technique that works well - but I could see how a novice could get lost reading it.

It is fairly easy. Assume your black text / white background css file is called bw.css and assume your white text / black background css file is wb.css

Download the styleswitcher.js file from the linked article and put it in the same folder as your html files. Then, in the head section of your index.html file, insert:

[CODE]<link rel="stylesheet" type="text/css" href="bw.css" title="black on white" />
<link rel="alternate stylesheet" type="text/css" href="wb.css" title="white on black" />
<script type="text/javascript" src="styleswitcher.js"></script>[/CODE]


Then in the body of your page, the actual links:

[CODE]<a href="#"
onclick="setActiveStyleSheet('black on white');
return false;">change style to black text on white background</a>

<a href="#"
onclick="setActiveStyleSheet('white on black');
return false;">change style to white text on black background</a>[/CODE]


If you put the head part of this in the head section of EVERY page in your site, then the style will apply to each page.

Cheers

Graeme
Copy linkTweet thisAlerts:
@doggydoodooauthorNov 08.2006 — Thank you so much, nut I think my computer's messed up or something, because this is the second or maybe third time it hasn't worked, yet everybody else says it does. Thanks for all the help!!
Copy linkTweet thisAlerts:
@doggydoodooauthorNov 08.2006 — Oops, sorry, I meant [I]something[/I] doesn't work, not [I]it[/I].
×

Success!

Help @doggydoodoo 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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