Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-03-2009
Member
 
Join Date: Feb 2009
Posts: 117
Can we Write conditional statements in CSS?

Hello,

Can anyone tell me, whether we could write conditional statements in CSS and if it is possible which programing language could we use to write that?

As far as i know CSS related to Cascading style sheet and it is possible to write in HTML format and if it possible in HTML then can we write this same for IE 7 or IE 8.

Thanks for your help...
Reply With Quote
  #2  
Old 04-03-2009
Member
 
Join Date: Jan 2009
Posts: 163
Re: Can we Write conditional statements in CSS?

Since conditional comments use the HTML comment structure, they can only be included in HTML files, and not in CSS files. I'd have preferred to put the special styles in the CSS file, but that's impossible. You can also put an entire new <link> tag in the conditional comment referring to an extra style sheet.

Code:

Code:
<p><!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->
Reply With Quote
  #3  
Old 04-03-2009
Member
 
Join Date: Jan 2009
Posts: 96
Re: Can we Write conditional statements in CSS?

Conditional comments are proprietary to Microsoft's browser, but because they reside within standard html comments, they do not
cause validation problems with your code or problems with other browsers.

Conditional css is also proprietary to Internet Explorer and is not part of the css standards. It will cause your css to be
non-standard. IE is the only browser that supports it. You're better off avoiding it if possible.
Reply With Quote
  #4  
Old 04-03-2009
Member
 
Join Date: Mar 2008
Posts: 258
Re: Can we Write conditional statements in CSS?

yes conditional statements are possible in CSS, but they only argue browser types. You use them as "comments". However, you cannot put the statements in the CSS file itself. You have to put it in the HTML file since a CSS conditional statement is in the form of an HTML comment. See below:

Code:
<!--[if IE]>
Special instructions for Internet Explorer would go here
p{
margin:10px !important;
}
<![endif]-->
Or if you prefer you can make it more browser specific by adding EXACTLY which browser to change the settings on, like this:

Code:
<!--[if IE 5]>
This would change settings according to whether or not the user is using Internet Explorer 5
<![endif]-->
You can also use "lt", "gt", or "lte" to specify which browser, like this:

Code:
<!--[if gt IE 6]>
This would change settings if the browser was GREATER THAN (gt) Internet Explorer 6<br />
<![endif]-->
"lte" would stand for "Less Than or Equal to"
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Can we Write conditional statements in CSS?"
Thread Thread Starter Forum Replies Last Post
Conditional statements in C sharp Vaikuntam Software Development 3 16-12-2010 08:36 AM
Conditional statements in batch files Gillian Anderson Software Development 5 01-04-2010 11:21 AM
Difference between DML statements and DDL statements Prashobh Mallu Software Development 5 11-01-2010 01:07 PM
Problem with my IF ELSE IF statements in C++ KACY5 Software Development 2 04-09-2009 05:12 PM
SQL statements with JSP blindsleeper Software Development 2 16-05-2009 09:54 PM


All times are GMT +5.5. The time now is 02:34 AM.