简体   繁体   中英

Set CSS to dynamically created class

I have multiple <ul> and their class names are pulled from database. User can add or delete those unordered lists and give them any name they wish. Then user can assign color to every <ul> . I can save color to database but I don't know how to load it to css because I have to select class which name I don't know and set some color to background-color atribute. This is how I load list:

<ul class="<?php echo $stringTemp; ?>">

This is placed in while loop. Now I need help to put background color to each of these lists.

嗯,只是style="background-color: xxx"

<?php
echo "<style>
           .myClass {
                background-color:$stringTemp;
            }
 </style>";

 echo "<ul class='$myClass'>       </ul>";

 ?>

Make a file called style.css and put this in it:

ul.class-one { background-color: #000; }
ul.class-two { background-color: #F00; }
ul.class-etcetc...

and add this to your HTML <head> section:

<link rel="stylesheet" type="text/html" src="style.css">

You probably know how to do this already I just want to be thorough for others reading this.

Try this one it

<?php

        while()
        {
    echo"<ul class='".$stringTemp."'>";
        }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM