tuankhoa1996 tuankhoa1996 - 5 months ago 33x
Python Question

One class with different CSS values in Flask/Jinja2 using jQuery

I want to set multiple css value for one class. Is that possible?

My template looks like this:

{% block right %}
{% for announce in announce_list %}
<div class="announce">
<div class="announce-info">
<span class="announce-title">
</span> <br/>
<span class="announce-date">
<div class="announce-author">
<div class="author-avatar">
<img src="{{url_for('static', filename='avatars/' + announce.author.avatar)}}">
<div class="author-info">
<span class="author-name">
</span> <br/>
<span class="author-level">
{% endfor %}
{% endblock %}

Each announce in for loop contains a Author object with a variable color (example: #B22222). I want to style the border color of each
block with the color of the Author object. Please help!

Sorry about my english!


Variable styles cannot be represented by CSS classes. In this case, you should use inline style attributes on each div using Jinja2's template syntax:

<div class="announce-author" style="border-color: {{announce.author.color}};">