• support@answerspoint.com

Can you use if/else conditions in CSS?


I would like to use conditions in my CSS.

The idea is that I have a variable that I replace when the site is run to generate the right style-sheet.

I want it so that according to this variable the style-sheet changes!

It looks like:

[if {var} eq 2 ]
    background-position : 150px 8px;
    background-position : 4px 8px; 

Can this be done? How do you do this?

  • CSS

  • asked 6 years ago
  • Gul Hafiz



No, but you can use classes for this, if you have access to the HTML. Consider this:

<p class="normal">Text</p>

<p class="active">Text</p>


and in your CSS file:

p.normal {
  background-position : 150px 8px;
p.active {
  background-position : 4px 8px;

. You can do it the way of CSS.

  • answered 6 years ago
  • Community  wiki

Your Answer

    Facebook Share        
  • asked 6 years ago
  • viewed 1812 times
  • active 6 years ago

Best Rated Questions