I'm at a loss as to what is happening here. I'm getting undesired spaces between span elements when I use indentation in the template. Ie:
<div>
<span class="empty-space"></span>
{% for dia in dias %}
<span class="{% cycle "dia-par" "dia-impar" %}">{{ dia }}</span>
{% endfor %}
</div>
So I'm forced to write the less readable form:
<div>
<span class="empty-space"></span>{% for dia in dias %}<span class="{% cycle "dia-par" "dia-impar" %}">{{ dia }}</span>{% endfor %}
</div>
To get the desired functionality. I already tried with margin-left/right:0px. and {%spaceless%}. Any Ideas what is going on?
The span is an inline element so white space is taken into an account.
Django has a spaceless
tag which you can use to resolve this, as that removes the spaces between tags:
https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#spaceless
It allows you to keep the template structure as is, but the output would be without the extra spaces.
You can also attack it from the CSS level, and set the span's display
to inline-block
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With