How do you change the style of a div programmatically

后端 未结 8 2598
攒了一身酷
攒了一身酷 2021-02-20 06:56

How do I change the style (color) of a div such as the following?

\"
8条回答
  •  梦如初夏
    2021-02-20 07:09

    It looks like you are writing ASP, or maybe JSP. I'm not too familiar with either language, but the principles are the same no matter what language you are working in.

    If you are working with a limited number of colours, then the usual option is to create a number of classes and write rule-sets for them in your stylesheet:

    
    .important { background: red; }
    .todo { background: blue; }
    

    And so on.

    Then have your server side script generate the HTML to make the CSS match:

    
    

    You should, of course, ensure that the information is available through means other than colour as well.

    If the colours are determined at run time, then you can generate style attributes:

    
    

提交回复
热议问题