I need to create a div with specific background-color depending on variable object.
My options are:
I know style should be separated from html. But, in this case, what is more efficient?
Do you need a different color based on dynamic content ("variable object")? In that case you should go for an inline-style. It would be easy for php/whatever backend you have to serve it conditionally.
While it's best to keep most styles on a stylesheet, there are exceptions to that rule. If your particular case asks for it, feel free to add your styles inline. For example, you need a gallery of things and you need the elements with a background-image instead of an img.
No, you cannot . The options you provided are the only way... You can do a complex/advance JavaScript
/ jQuery
but it will always boil down to on how you will provide the selectors
.
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.