By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

Changing CSS Styles in a main page

P: 3
Hi, everyone!

I hope you guys can help me. I´m working on a website which deals with 4 different css styles. Once in the Homepage, the user can choose one link out of four to enter the site. Depending on the link he chooses, all the following pages will follow a different style. So, my question is: how can I make this decision taken in Home to be understood by all the other pages? The css style they´ll load depends on this previous choice.. I´ve searched the web after sollutions and I think Javascript can help me, but I know just a little about it. Can you help me? I know what I have to do, theorically, but I don´t know how to translate it into a code..

Thank you all,

Rafael
Oct 24 '08 #1
Share this Question
Share on Google+
6 Replies


Nepomuk
Expert 2.5K+
P: 3,112
...I´ve searched the web after sollutions and I think Javascript can help me, but I know just a little about it. Can you help me?
Hi Rafaell!
Obviously, you have made the same mistake as many newbies do - you confused Java with JavaScript. They aren't the same, actually not even very closely related (although the syntax has quite a few similarities). I'm moving this to the JavaScript Forum, where it belongs. Good luck with your task!

Greetings,
Nepomuk (Moderator)
Oct 24 '08 #2

P: 55
I know what I have to do, theorically
what....theoretically.... would you like to do?
Do you want to change css classes you have already defined?
Are you looking to define and handle all classes in javascript?
There are ways to do either of these, and more....do you have a page started?

the basics are:

Expand|Select|Wrap|Line Numbers
  1.      myHTMLElement.style.border="2px red groove"
  2.      myHTMLElement.style.zIndex=3
  3.  
  4. or
  5.  
  6.      myHTMLElement.className="myClassName"
  7.  
Oct 25 '08 #3

P: 3
Hi Rafaell!
Obviously, you have made the same mistake as many newbies do - you confused Java with JavaScript. They aren't the same, actually not even very closely related (although the syntax has quite a few similarities). I'm moving this to the JavaScript Forum, where it belongs. Good luck with your task!

Greetings,
Nepomuk (Moderator)

Thank you! Hope I´ll be luckier now.
Oct 25 '08 #4

P: 3
what....theoretically.... would you like to do?
Do you want to change css classes you have already defined?
Are you looking to define and handle all classes in javascript?
There are ways to do either of these, and more....do you have a page started?

the basics are:

Expand|Select|Wrap|Line Numbers
  1.      myHTMLElement.style.border="2px red groove"
  2.      myHTMLElement.style.zIndex=3
  3.  
  4. or
  5.  
  6.      myHTMLElement.className="myClassName"
  7.  

Hi, zaphod42!

Thanks for your reply. I have four .css files. In the main page, I want the user to choose among four ways of loading the other pages, each way will load a .css style. The user will chose this by clicking on a link. I don´t want to change the .css files itself. And I have only a few functions in javascript.

I still don´t have the main page coded, but every other page, by now, has this line in its code:
Expand|Select|Wrap|Line Numbers
  1. <link rel="stylesheet" type="text/css" href="FILE.css" />
The point, I guess, is that this line shouldn´t be in each page, at least not with this "FILE.css" defined, because the instruction of loading a specific CSS file has to be given by the link in which I clicked in the main page. Is there a way to make LINK_1 on the main page load the FILE_1.css in every other page, and LINK_2 load FILE_2.css and so on?
Oct 25 '08 #5

P: 55
if you want to do it client side you could add a hash to the url to tell the pages which link was clicked...but you would also have to add that hash to and local links on your page to ensure the style loads properly
Oct 25 '08 #6

acoder
Expert Mod 15k+
P: 16,027
It would make sense to do this via the server-side, so that the CSS file is loaded during page load. You can use JavaScript if you want. Use cookies to store the preference. You may find this article useful.
Oct 25 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.