Control CSS dynamically via PHP

Asked

Viewed 343 times

-2

I am developing a site, and also a content manager for him, in the manager I control the images of the site and the texts, I wonder if there is any way for me to control the font color and the font type of the texts, ie in the manager, have a color Picker (or something similar) for the user to choose the font color of a given text, and also some way to choose which font type (Times New Roman, Arial, Comic Sans, and others). Any suggestions ?

  • Look, there are several ways to do this. You can generate a.css file on the server... You can save css snippets and render on the screen... etc. You should choose a shape and do it. I think you will find a lot of content on the internet

  • Poisé , I know there are several ways to do this, so I asked Suggestions ...

  • 1

    I think your question seems too broad to get a concrete answer, so the negative votes. Anyway, you can get the hexadecimal of a color through a Color Picker and save it in a database, for example, something like #FF0000. Then you load this information and define it via javascript.

  • 1

    Now, looking at it from another angle, maybe you’re asking about Ckeditor or Tinymce, which are text editors that you can embed in your manager.

  • Exact, I’m thinking of having a Picker color to select the color and then save the hexadecimal code or rgb and change in the main page css

1 answer

2

You can write dynamic CSS with PHP YES, advise? good, for beginners is a good idea but if you already have some knowledge in javascript be it intermediate/advanced, you can already use more appropriate tools for this as LESS/SASS, coupled to tools such as Webpack, they work very well.

to write CSS with PHP just set your header and imports it to the page where you want to style example...

PHP

<?php

header("Content-type: text/css");
$cor_fundo = "#999";    

?>

body {
background: <?=$cor_fundo?>;
}

HTML

<link rel="stylesheet" href="estilo.php" type="text/css" />

With this in mind, you can manually manipulate variables, or build a panel to interact with the code...

  • I could control this variable (in this example $cor_background) by another page (the manager page), then when I change the color and save, it is saved (or sent) in the css of the main page ?

  • 1

    can yes, and has several forms, one of them is to create a json file with the settings of the variables, and in the panel read, edit and save these settings, in the php(css) file you read these settings and apply them...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.