By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Can you use if/else conditions in CSS?

MusoFreak200
P: 96
I would like to use conditions in my CSS.

The reason is because for the life of me i cannot work out how to get linear gradients to display in IE browsers so i want to have browser to display an image instead if the browser is an IE browser and to display the linear gradient code if it is any other browser.

so far my code looks like this:

Expand|Select|Wrap|Line Numbers
  1. #rightsidegradientbar 
  2. {
  3.     width:50px;
  4. background-image: -webkit-gradient(
  5.     linear,
  6.     right bottom,
  7.     left bottom,
  8.     color-stop(0.1, #FFFFFF),
  9.     color-stop(0.78, #00CCCC),
  10.     color-stop(1, #00CCCC)
  11. );
  12. background-image: -moz-linear-gradient(
  13.     right center,
  14.     #FFFFFF 10%,
  15.     #00CCCC 78%,
  16.     #00CCCC 100%
  17. );
  18. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFF', endColorstr='#00CCCC');}
  19.  
if you would like to check out my most recent question it is linked here:
http://bytes.com/topic/html-css/answ...ts#post3665036

thank you in advance for any help or suggestions that you may be able to pose.
Jul 2 '11 #1

✓ answered by Sudaraka

Programming concepts like decision making and iteration (if/else and loops) are not available in CSS, as CSS is not a programing language.

However, in IE (only) you can use HTML conditional comments in include different style sheets (.css files or <style> tags) so that different CSS can be applied to the document in different conditions (i.e. different IE versions)

http://www.javascriptkit.com/howto/cc2.shtml

Share this Question
Share on Google+
2 Replies


Sudaraka
P: 55
Programming concepts like decision making and iteration (if/else and loops) are not available in CSS, as CSS is not a programing language.

However, in IE (only) you can use HTML conditional comments in include different style sheets (.css files or <style> tags) so that different CSS can be applied to the document in different conditions (i.e. different IE versions)

http://www.javascriptkit.com/howto/cc2.shtml
Jul 3 '11 #2

MusoFreak200
P: 96
thank you heaps sudaraka but i have solved my own gradient problem..

but i am very interested in your link and post so i will mark it as answer
Jul 3 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.