Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change CSS style easily?

Status
Not open for further replies.

mancroft

Programmer
Joined
Oct 26, 2002
Messages
267
Location
GB
Change CSS style easily?

Is there an easy way for a user to change the CSS style sheet easily and permanently without changing the style sheet itself directly but instead changing some sort of input boxes setup in php (if you know what I mean!)?
 
Your question is kind of confusing - but to give you a short answer:
AFAIK PHP has no settings for appearance of input boxes.
That's all client side with interpretation od CSS. You might want to check in the CSS forum for advanced techniques in CSS. You can override styles or use alternate stylesheets, but the PHP forum probably is an unlikely place to get the best answer for the question.
 
I think what he wants to do is to dynamically write the CSS file based on some user input...yes, this is possible, though one page at least will need to be generic so it can be accessed by the user the first time visit...

You can use PHP to open/read and write to the CSS file and make that available to the next page...

hth


Bastien

Cat, the other other white meat
 
How about using a session variable to record the current CSS choice, and on page load echo out the appropriate CSS linked file. That would provide the solution you want, in PHP, without doing "permanent" changes to the CSS file itself.

This would be great for allowing the user to flick between "normal" and "big text/black+white" mode (for those with accessability issues), or to provide a "text only" version versus a "graphics heavy version".

If you stored the CSS choice in a cookie client-side, then your visitor setting would persist across sessions too.

Jeff
 
If you know what the user wants to change to (let's assume you askd them through a form and stored the details in a db)) you can when you come to generate a page you could do something like <table style="<?php echo $tablepref?>">, your not limited to using a file when using CSS.
If the user is CSS savvy, you could save a CSS file on the PC and use javascript to switch to it,perhaps from the onload event on the <body> tag.
 
Why not just put
Code:
<link href="mystyle.php" rel="stylesheet" type="text/css">
in your html and then generate mystyle.php on the fly?
 
ericbrunson (TechnicalUser) May 11, 2004 said:

Why not just put

CODE

in your html and then generate mystyle.php on the fly?


Please elucidate "generate mystyle.php on the fly?".
 
I think mystyle.php would just output code that looks like an external css file containing style definitions.
A cookie on the client machine or a database stored profile could supply the specific parameters for the customized styles. The predefined style names are populated with colors, font etc. information.
 
The HTML would try to resolve a file called mystyle.php from the server, so you would need to somehow identify specific occurences of the file e.g. ingresmanstyle.php (well actually .css) but that would be a real load of files if you had a load if users. You might get away with C:\files\mystyle.php but you would have to know the file system, get the user to set it up etc.
Storing in a cookie ?, cookies are limited in size and not very thin client i.e. move PC and you loose your style which is gaurenteed to irritate users . As I said in a previous post you will need to capture the details somewhere as a user cant just change the style on his PC in an ad-hoc way, store in it the db and generate it at page creation time.
It would be an interesting little project to create a generic style collection screen to drop into any app which wanted to allow personalisation
[steps down from box]
 
ericbrunson hit the nail on the head and DRJ clarified... but since it seems to be being missed, please don't be too upset if I try to reword.

Using ericbrunson's line somewhere in your HTML file and then imagine this as mystyle.php

Code:
<?php
if (date(n) < 5) {
  echo 'body {
background: #000000;
color: #FFFFFF;
}';
else {
  echo 'body {
background: #FFFFFF;
color: #000000;
}
?>

Then that's it, for Jan, March, Feb & Apr you can have black text on white background, and for the rest of the year white on black.

Obviouslly you'd put more useful things in mystyle.php, but the point is all the echo/print statements would be used to output valid CSS, just as we normally use echo/print to output valid HTML. Go ahead and use cookies or databases or random number generators... the important point is that you output valid CSS.
 
2 ways to get this done:
- store user pref. of CSS in the DB and call it/echo it on logon into a session variable
- give a user option to switch between "looks" by setting a cookie on their system

AKA "SKINS"


:------------------------------------:
fugitive.gif

ok,ok...I did shoot the deputy but he told me he was the sheriff!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top