How To Change Css Styles Dynamically Using Php/mysql..i Want To Create Themes That Are Unique To Each User?
Solution 1:
There are various ways this can be done. 1. Convert your CSS to PHP, i.e. CSS is generated, but everything can be dynamic - probably overkill for a few colours 2. Overwrite the styles in the stylesheet
The simplest way, probably not the best though is number 2, over write the style after the stylesheet with the new colour.
i.e (sudo code)
<html><head>
....
<style...src="..." /><style>
// from db
#custom { background: #<?phpecho$colour; ?> }
</style>
etc
Solution 2:
It is better you use your JavaScript to change the style between PHP tags.
For example:
if($response){
echo "<script>
$('#matter_table').css('display', 'block');
</script>";
}
else{
echo "<script>
$('#matter_table').css('display', 'none');
</script>";
}
Solution 3:
I use this trick :
I create a dynamicss.php file and in it use :
$color = '#6b82a2';
$css = <<<HERE
body{
font-family:Arial, Helvetica, sans-serif;
background-color : $color ;
background-image: url("../img/texture.png");
}
HERE;
$bytes = file_put_contents('css/mainCss.css',$css);
you can load your variables and then use in hereDoc.
Solution 4:
You can achieve this by following steps:
Make your website template flexible if user change one style it should reflect on all theme.
When user logged in you can fetch that user theme color from db and you can store it on session or any other possible way.
e.g : $themecolor = '#000000';
Pass that theme color to body background inline style
e.g : style = "background-color : <?phpecho$themecolor; ?>"
Post a Comment for "How To Change Css Styles Dynamically Using Php/mysql..i Want To Create Themes That Are Unique To Each User?"