0

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.

3
  • Can you show the whole code including the SQL query and others ? Commented Oct 5, 2013 at 16:34
  • @Alen: You can use a template library like underscore , duster or mustache. It's easy to do in that. Provided you have the data on the page load. Commented Oct 5, 2013 at 16:39
  • Use inline css <ul style='background-color:$stringTemp;'> Commented Oct 5, 2013 at 16:39

4 Answers 4

3

Uhm, just style="background-color: xxx" ?

Sign up to request clarification or add additional context in comments.

3 Comments

Will this work for mutliple styles. I have to set gradient but since gradient is part of CSS3 I have to make seperate styles for multiple browsers?
You can see the standard syntax here. Browser support here.
@Alen multiple styles as in multiple properties? Sure: style="background-color: xxx; background-image: -webkit-xxx; background-image: -moz-xxx;"
1
<?php
echo "<style>
           .myClass {
                background-color:$stringTemp;
            }
 </style>";

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

 ?>

1 Comment

I like this better than mine but you put .myClass in the PHP instead of . " . $myClass . " {. +1 though
0

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.

Comments

0

Try this one it

<?php

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.