
Question:
I would like to set up one single css style which gets the background dynamically from some django variable.
I think the added difficulty is that it is related to a:hover.
The original static style.css code runs like:
.titles-button h2 a {
margin-left: 4em;
margin-right: 4em;
margin-top: 1em;
margin-bottom: 1em;
display: block;
width: 240px;
height: 80px;
/* background: transparent url(../logos/djangoVX_logo.png) center left no-repeat; */
text-indent: -999em;
border: 1px dashed green;
}
.titles-button h2 a:hover {
/* background: transparent url(../logos/djangoVX_logo2.png) center left no-repeat; */
}
Note the background is now commented.
I would like to use this style within a DIV and update dynamically the background.
Like:
{% if the_apps_list %}
{% for apps in the_apps_list %}
<div class="titles-button">
<h2><a href="/{{ apps.app_name }}/" style="X">{{ apps.app_name }}</a></h2>
</div>
{% endfor %}
{% else %}
No APPS are available. Internal Error.
{% endif %}
I did my best for "X" but with no results.
With the exception of: - Rewrite the full style in X - Use some javascript fancy stuff (on_mouse_over...) - I have even seen a class: inheritALL
None of this solution fits my idea of using django.
I might get the bull from the wrong side...
..which one is the right side?
cheers F
Answer1:Let's say you have "dark" and "light" versions of background. Your code may look like:
<strong>views.py:</strong>
...
if i_want_dark_version:
context['style']='dark'
else:
context['style']='light'
<strong>template.html:</strong>
<div id="titles-button" class="{{ style }}">
...
</div>
<strong>style.css:</strong>
#titles-button.dark h2 a {
background: ...;
}
#titles-button.dark h2 a:hover {
background: ...;
}
#titles-button.light h2 a {
background: ...;
}
#titles-button.light h2 a:hover {
background: ...;
}