0

Actually I'm working with a programming app. Now I would like to add a default theme color. This default theme color adding from general setting page using php. And I'm added a new css like default-theme.css. But how to get this color code & use this color code in default-theme.css?

HTML codes: (from general setting page)

<div class="form-group">
        <label for="default_theme_color" class="col-md-2">
           <?php echo lang('default_theme_color'); ?>
       </label>
       <div class="col-md-10">
           <?php $this->load->view("settings/default_color_plate"); ?>
       </div>
</div> 

Note:

  • I'm use hare a color plate (default_color_plate) include some color:
("#00BCD4", "#17a589", "#2471a3", "#2e4053", "#2e86c1", "#404040", "#555a61", "#557bbb", "#839192", "#83c340", "#884ea0", "#a6acaf", "#a93226", "#d68910"). 

Saved a default color code from the color plate. And get this color code from database. But how do I work with css to use this color code?

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
  • Try to close your questions and choose the correct answers, because building a bad reputation of not closing the questions will not encourage anyone to answer your questions anymore. – Sherif Salah Jun 20 '19 at 12:40

2 Answers2

0

Check this link on how to use php in css: CSS Variables with PHP.

If you want to use variables from general settings page file, you can require that file in your style.php. But the best solution would be to create class in separate file to hold that colour variables and require file with that class in both, general settings page file and style.php, unless your colours are already stored in some class. If I understand correctly you are keeping the colours you want to use in default-theme.css, in a database? Then you could change defalut-theme.css to default-theme.php and make queries to that database to retrive colours you need.

Also this questions might help you:

  1. How to use PHP inside css file
  2. How do i run PHP inside CSS
Roirraw
  • 93
  • 7
0

You can simply use css variables in your page header define your css variables above your styles and they will all see your variables and you can use them in any stylesheet:

<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <style>
        :root {
            --color-white: <?= $whiteColor ?>;
            --color-black: <?= $blackColor ?>;
        }
    </style>
    <!-- your styles -->

Now in any stylesheet you can use these two variables:

.text-white {
    color: var(--color-white);
}

.text-black {
    color: var(--color-black);
}
Sherif Salah
  • 2,085
  • 2
  • 9
  • 21