RalpawTato RalpawTato - 9 months ago 55
CSS Question

CSS File manipulation with PHP

Is it possible to edit a specific selector in a css file with php?

For example:

background-color: #FFFFFF;

I want to change this background color after the user changes the background color of the website from the website's settings.


This website is used only by one user.

I am using Laravel 5.3 if that helps.

The way it would work is, there's a color picker for the background color of the body and then when the user submits the form. Then the file manipulation will happen there.

Answer Source

You can do like like

$color_name = 'green';
<body style="background-color:<?php echo color_name ; ?>">
  Body elements

However its not a good idea to change this with php in my opinion.You have to make a get/post request to change this. Its better to do this with jquery

<body class="change_backgroud_color">
  Body Elements

   $(".change_backgroud_color").css("background-color", "yellow");