Built-in css for multiple elements

I am trying to use inline css because I have some parameters that I need to pass that I cannot do in css files. Everything is fine if I set the style for one element, for example:

<div class="example" style="background-color:#**<?=$model->color?>**">

But since it requires a lot of elements, can this color parameter be placed in one style? If in css I do it like this:

.example h1, h2, li, p a {color: red};

I am trying to do this in embedded CSS, but it does not work:

<div class="example" style="h1, h2, li, p a color:#**<?=$model->theme_color;?>**">

Does anyone know how to do this? And can I do it inline?

+4
source share
4 answers

It should do it

<?php
echo "<style>
    .example h1, h2, li, p a {
        color: $model->theme_color
    }
    </style>";
?>

Another way:

<style>
    .example h1, h2, li, p a {
        color: <?php echo $model->theme_color; ?>;
    }
</style>
+4
source

, , CSS ( CSS) - , CSS . -

<!-- your external CSS files -->
<style>
   h1, h2, li, p a { color:#**<?=$model->theme_color;?>** }
</style>
<body>
   <!-- your HTML -->
</body>
+4

/ CSS? -

<div class="color-<?=$model->color?>">

CSS

.color-red {color:red;}
+4

Try as follows:

<?php
echo "
    <style>
    .example h1, h2, li, p a {
    color: #".$model->theme_color."
    }
    </style>
";
?>
+2
source

All Articles