Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline css for several elements

Tags:

html

css

I'm trying to use inline css because I have some parameters I need to pass which I can't do it 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 because there are lots of elements need that color parameter, can I put all of them in one style? If in css, I do it like this :

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

I'm trying this in inline css but it doesn't work :

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

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

like image 394
Anthonius Avatar asked Dec 07 '22 23:12

Anthonius


2 Answers

This 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>
like image 126
dorado Avatar answered Dec 24 '22 04:12

dorado


What you probably need is internal CSS (instead of inline CSS) - that's where you include your CSS within style tags. So something like

<!-- your external CSS files -->
<style>
   h1, h2, li, p a { color:#**<?=$model->theme_color;?>** }
</style>
<body>
   <!-- your HTML -->
</body>
like image 45
potatopeelings Avatar answered Dec 24 '22 05:12

potatopeelings