Results 1 to 4 of 4

Thread: Can we Write conditional statements in CSS?

  1. #1
    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...

  2. #2
    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]-->

  3. #3
    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.

  4. #4
    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"

Similar Threads

  1. Conditional statements in C sharp
    By Vaikuntam in forum Software Development
    Replies: 3
    Last Post: 16-12-2010, 08:36 AM
  2. Conditional statements in batch files
    By Gillian Anderson in forum Software Development
    Replies: 5
    Last Post: 01-04-2010, 11:21 AM
  3. Difference between DML statements and DDL statements
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 11-01-2010, 01:07 PM
  4. Problem with my IF ELSE IF statements in C++
    By KACY5 in forum Software Development
    Replies: 2
    Last Post: 04-09-2009, 05:12 PM
  5. SQL statements with JSP
    By blindsleeper in forum Software Development
    Replies: 2
    Last Post: 16-05-2009, 09:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,145,119.29013 seconds with 16 queries