# Using Conditional Statement within Code

**URL:** <https://forum.kirupa.com/t/using-conditional-statement-within-code/263654>\
**Category:** web dev\
**Created:** [June 18, 2008, 12:40am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654 "2008-06-18T00:40:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [June 18, 2008, 12:40am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/1 "2008-06-18T00:40:34Z")

</div>

Is this the correct syntax? I can’t get my browsers to recognize the conditional:

```auto

div#content.splashtext h2 {
    color: #ffffff;
    font-size: 22px;
    /* IE6 Only: */
    <!--[if IE 6]>
    margin-right: 200px;
    margin-left: 320px;
    <![endif]-->
}

```

---

<div class="post-metadata">

**Author:** ![fasterthanlight](https://avatars.discourse-cdn.com/v4/letter/f/ecc23a/32.png) [@fasterthanlight](https://forum.kirupa.com/u/fasterthanlight)\
**Post date:** [June 18, 2008, 12:52am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/2 "2008-06-18T00:52:12Z")

</div>

have you tried other variants?

I don’t really use this method, but here, this looks useful:

[http://www.quirksmode.org/css/condcom.html](http://www.quirksmode.org/css/condcom.html)

---

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [June 18, 2008, 12:58am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/3 "2008-06-18T00:58:43Z")

</div>

I’ve seen that page, yes. I’m wondering if there is an issue with placing the conditional within CSS code, or if it’s only used within HTML code or to link to external stylesheets.

---

<div class="post-metadata">

**Author:** ![fasterthanlight](https://avatars.discourse-cdn.com/v4/letter/f/ecc23a/32.png) [@fasterthanlight](https://forum.kirupa.com/u/fasterthanlight)\
**Post date:** [June 18, 2008, 1:01am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/4 "2008-06-18T01:01:47Z")

</div>

Bingo! That would make sense me thinks!

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 18, 2008, 2:03am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/5 "2008-06-18T02:03:28Z")

</div>

No, the conditional statement ‘\<!–[if IE 6]\> … etc’ is not valid css and won’t be rendered. The conditions are made to load separate css files.

However, you don’t need to fret about making two complete ones. Make a base and then add the things that don’t work to the ie6 one as;

begin ie6.css

```auto

@charset "UTF-8";
#yadayada li {
margin-top:none !important;
}

```

And just keep it to that. That way there’s little need to maintain two complete stylesheets… just a base one and then the ie hacks ; )

---

<div class="post-metadata">

**Author:** ![fasterthanlight](https://avatars.discourse-cdn.com/v4/letter/f/ecc23a/32.png) [@fasterthanlight](https://forum.kirupa.com/u/fasterthanlight)\
**Post date:** [June 18, 2008, 2:18am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/6 "2008-06-18T02:18:45Z")

</div>

Yea, and alternatively, if you want to keep everything in one stylesheet, you can bypass the entire conditional thing and use \* html

```auto

div#content.splashtext h2 {
    color: #ffffff;
    font-size: 22px;
}

* html div#content.splashtext h2 {
    margin-right: 200px;
    margin-left: 320px;
}

```

---

<div class="post-metadata">

**Author:** ![yann](https://avatars.discourse-cdn.com/v4/letter/y/bc79bd/32.png) [@yann](https://forum.kirupa.com/u/yann)\
**Post date:** [June 19, 2008, 10:49pm UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/7 "2008-06-19T22:49:44Z")

</div>

slight nitpicking: conditional comments are not only for linking to external style sheet, you can also put a few CSS declarations in there. But yes, it’s meant to be in the HTML header, not in the CSS

---

<div class="post-metadata">

**Author:** ![evildrummer](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/evildrummer/32/2308_2.png) [@evildrummer](https://forum.kirupa.com/u/evildrummer)\
**Post date:** [June 20, 2008, 12:11am UTC](https://forum.kirupa.com/t/using-conditional-statement-within-code/263654/8 "2008-06-20T00:11:52Z")

</div>

Reason it works that way is because IE’s conditionals are in HTML comments that are incorrect syntax for a CSS parser so just returns an error (browser ignores it). It’s always easier to just have an external stylesheet, and most of the time there’s more than one fix needed
