doubledee — 2010-09-21T23:03:30-04:00 — #1
Is it possible to create a dynamic Style Sheet?
I would like to create web page for my portfolio where a user could select a choice (e.g. radio button) and have that change what is in my CSS Style Sheet so that a particular element changes across the board.
Does that make sense?! :-/
doubledee — 2010-09-22T18:49:53-04:00 — #2
We can grow old together!
alexdawson — 2010-09-23T03:41:16-04:00 — #3
alexdawson — 2010-09-22T11:52:18-04:00 — #4
See, what you're asking for is the CSS to change itself which isn't possible because CSS isn't a dynamic language, it's static like HTML. When HTML changes dynamically it's not due to the HTML, it's due to the PHP altering the HTML. Therefore the only way to change the code would be to use scripting or PHP or something to make the dynamic changes as the code is rendered. Which is why you'd need to use scripting - to make the stuff happen as you need it.
I thought it was either Santa (pre-diabetes) or Darwin (looking particularly curious)
Yes it is possible... you would need to set no-caching to the CSS file (as you said) in htaccess (actually perhaps if the code changes it won't fetch the cached version) and you would use something like this (you could do a style.php file)... http://fwebde.com/css/php-dynamic-css/
ryanreese — 2010-09-22T10:49:57-04:00 — #5
Instead of using $GET which loads variables in the URL string, he could use $POST which would keep the information clean from the URL and strictly on the server side
system — 2010-09-23T02:04:29-04:00 — #6
For something like this, you don't even need jquery.
doubledee — 2010-09-22T19:03:56-04:00 — #7
doubledee — 2010-09-22T19:03:16-04:00 — #8
Could you use PHP to "build" a CSS stylesheet on the fly?
What I was envisioning - forgetting fast - is an ability to be able to click check boxes or radio buttons in a control panel and then have it change the style of elements.
Not the same as having 3 stylesheets on hand, mind you, but a way to tweak things more.
Say I want to change all control from white to light blue, and make my background dark blue from white, and my text from black to white. I could click those element boxes and voilà, things change.
Next maybe I'd make the control yellow, text red, and leave the background white.
I just think that would be a good way to do a "website color scheme picker" as well as show people the power of CSS!
ryanreese — 2010-09-22T18:54:47-04:00 — #9
doubledee — 2010-09-23T14:11:01-04:00 — #10
Kalon, that is sorta what I was envisioning, although I like the link Alex posted which used PHP better since it is more user-proof!
Thanks just the same!
doubledee — 2010-09-23T14:09:23-04:00 — #11
stomme_poes — 2010-09-23T04:29:01-04:00 — #12
Meh, depends on how important changing styles is. If changing colour doesn't change content, I don't see why it can't be in JS.
If it's changing something important, then I'd start getting worried (display: none/block).
chroniclemaster1 — 2010-09-23T00:44:23-04:00 — #13
alexdawson — 2010-09-22T23:46:50-04:00 — #14
Indeed you can, if you visit the link I provided earlier it explains how to make a PHP powered stylesheet.
rayzur — 2010-09-21T23:56:02-04:00 — #15
Lol, I'm only 44
Sometimes it feels like 100 though
ryanreese — 2010-09-21T23:54:41-04:00 — #16
He isn't 100 (or close to it), his avatar is just of an old man.
doubledee — 2010-09-21T23:50:42-04:00 — #17
Thanks for the links! (I'll check them out tomorrow.)
P.S. Are you like 100?!
rayzur — 2010-09-21T23:39:10-04:00 — #18
As Ryan pointed out, that is done with a script. You will find several examples by doing a search for "Style Sheet Switcher".
Here is a tutorial that Eric put together.
doubledee — 2010-09-21T23:35:24-04:00 — #19
Did you follow my original question? (It's late and my brain is fading...)
I was thinking if you could change your CSS on the fly then you could give your website a whole different look (or elements inside it).
There isn't a why to change the CSS file itself on-the-fly sorta like how you can use PHP to change a web page's HTML on-the-fly?
ryanreese — 2010-09-21T23:11:56-04:00 — #20
You would need to incorporate JS into the mix (or PHP) depending on if you want it automatic or not
But CSS alone can't do this.
next page →