Is inline CSS in Django?
I heard recommendations saying that you should not use inline CSS, for example:
<div style="min-width: 10em;">...</div> but you should use class instead, separating CSS from HTML and (if possible) placing them in a separate CSS file.
So far so good; it all makes sense - at least as long as everything fits into your model.
Now I run Django and I want to say something like:
{% for a, b in bar %} <div style="min-width: {% widthratio ab 100 %}em;">...</div> {% endfor %} Is there a practical way to avoid inline CSS here? Or do I just need to break the "Norm"?
Since this is a calculated value, you should use inline CSS. Inline CSS exists for some reason: CSS that cannot be reused for multiple elements / pages / websites.
Since you cannot calculate from a CSS file, it obviously makes sense to use inline CSS here.
PS I am doing almost the same thing in the Django template, except mine, to center the image vertically and horizontally, and I have to use the actual proportions of the image to calculate the centering CSS, so I cannot use the class.