March 31, 2012

User specific stylesheet?

Question by user1305075

I have a website where a user chooses a template of their choice for their web page.

Once they’ve selected the template, I want them to be able to change some of the styles such as the font colour etc?

Is there a way I could do this?

I thought of perhaps storing the user specified stuff in a field in a database and then retrieve it and display as internal CSS?

Answer by Monojit

You may use a user.css (initially empty) for each user and then add data provided by user with !important override.

Answer by Starx

Yes

It is possible. But you will have to rely on Javascript to add the stylesheet, url selected.

Assuming you would be using a link to change the theme, using jQuery, you would do

$('#red').click(function (){
   $('#linktagid').attr('href','user_red.css');
});
...

Please fill the form - I will response as fast as I can!