• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Webmasters I have a question are conditional statements allowed in CSS?

Status
Not open for further replies.
I'm wanting to work a simple if-else statement into my webpage and I wanted to know if you can use conditional statement in CSS or do I need to look at something else.

What I would like to do is.

/* If userName != 'x' print Y */

/* else print Z*/


If someone could guide me to a good CSS online resource that would be great as well.
 

Nerevar

they call me "Man Gravy".
I don't know if it's possible or not, but if you're using conditional statements you really should be using a scripting language (Javascript, ASP, PHP, etc).
 
Nerevar said:
I don't know if it's possible or not, but if you're using conditional statements you really should be using a scripting language (Javascript, ASP, PHP, etc).


Probably so. This is for my blog that is hosted by blogger so I don't know if they would allow you to.
 

Rahul

Member
Technically the specification doesn't allow for conditional statements. Use the DOM for that (eg. change an element's ID or something depending on a condition, which will determine which style is applied).

Of course, the spec can't do anything about what you put in a comment and whether you want to, say, parse the .css file through a script and read out those conditional statements to do something. But why do that? Just put conditional statements in the script itself, or in javascript, which would write a <link/> or <style> tag depending on a condition.

W3Schools makes for an excellent CSS resource when you're just getting started: http://www.w3schools.com/css/default.asp
When you advance after that, use the spec and related pages: http://www.w3.org/Style/CSS/

Also read up on the various CSS weblogs and experts in the field, such as Eric Meyer (meyerweb.com) for various practical uses and useful things you can do to get around situations like the one you're bringin up.

If you REALLY want to apply stylesheets with conditions, have a look at XSL(T): http://www.w3.org/Style/XSL/
 
Status
Not open for further replies.
Top Bottom