Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Conditional CSS class based on Python If statement

How do you add a conditional CSS class based on a Python if statement in the following example to show the has-success has-feedback form element?

<div class="form-group {% if not error_username %} has-success has-feedback {% endif %}">
like image 848
Robert Avatar asked May 08 '17 22:05

Robert


People also ask

How to apply CSS for if condition?

No, We can not use if-else conditions in CSS as CSS doesn't support logics. But we can use some alternatives to if-else which are discussed below: Method 1: In this method, we will use classes in HTML file to achieve this. We will define different class names according to the conditions which we want to apply in CSS.

Can you put if statements in CSS?

No if/else, variables, functions, methods, etc. You cannot use if statements in CSS nor can you in HTML. They're not programming languages, there is no built logic.


1 Answers

Write if condition this way.

<div class="form-group {{'has-success has-feedback' if not error_username }}">
like image 53
SumanKalyan Avatar answered Oct 06 '22 19:10

SumanKalyan