1👍
✅
First of all – CSS class shouldn’t be a pure integer. So I use letters in my answer since numbers doesn’t work. Normally it should be something more descriptive though.
Define CSS rules like:
div.a ul{
display: none;
color: green;
}
div.a ul.a{
display: block;
}
div.c ul{
display: none;
color: red;
}
div.c ul.c{
display: block;
}
Here is the fiddle – http://jsfiddle.net/FC6vF/
The color
rule is just to mark the difference in the fiddle and you can omit this.
For Django template – put this code:
{% for css_class in fancy_css_classes %}
div.{{ css_class }} ul{
display: none;
color: red;
}
div.{{ css_class }} ul.{{ css_class }}{
display: block;
}
{% endfor %}
inside <style>...</style>
tag and pass the list of classes as a context variable fancy_css_classes
from your view.
Source:stackexchange.com