saurabh ranu
saurabh ranu

Reputation: 1371

assign li a background color of my choice

I have some colors on my server side. I have a list structure in the . When I am loading the jsp I want to assign a particular li a particular color. The color from server side can change as well as which li should be assigned a color depends upon server side so I can't include that color in css rules.

The structure I have is follows

 <ul>
  <li id="one" class="liClass" style="background-color:<%=Color %>">..(1)
  <div>...</div>
  <div>....<div>
  <select>...select</select>
  </li>
  <li id="two">
  <div>...</div>
  <div>....<div>
   <select>...select</select>
 </li>
</ul>

Can I do something like above?

Also can i have something like a div inside li tag and the div should occupy all inside li.?

Upvotes: 0

Views: 181

Answers (2)

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17576

in your code there are syntax errors

<li id="one" class="liClass" style="background-color:<%=Color %>">..(1)
  <div>...</div>
  <div>....<div>
  <select>...select</select>
  </li>

you used <div>....<div> it is incorrect

you used <select>...select</select> it is incorrect also

an also i think there is html errors in

<li id="one" class="liClass" style="background-color:<%=Color %>">..(1) line . 

please check those errors and correct them first .

UPDATE

first correct the HTML and then hard code the style="background-color: and check if it works . then try to add it dynamically .

start simply ok............ (that's my advice).............. ;)

Upvotes: 1

David Houde
David Houde

Reputation: 4778

Yes you can do this.

I would advise against inline styling though. I think it would be more appropriate to define these colors in a stylesheet (using the same serverside method if needed), and then generate a class="color_class" inside of the li element

Upvotes: 0

Related Questions