Django dynamic css implementation: only one item changes (background) dynamically. How to?
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 %}
<p>No APPS are available. Internal Error.</p>
{% endif %}
I did my best for "X" but with no results.
With the exception of: - Re开发者_运维百科write 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
Let's say you have "dark" and "light" versions of background. Your code may look like:
views.py:
...
if i_want_dark_version:
context['style']='dark'
else:
context['style']='light'
template.html:
<div id="titles-button" class="{{ style }}">
...
</div>
style.css:
#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: ...;
}
精彩评论