forward slash in CSS? Is this some browser specifi

2019-05-02 11:46发布

问题:

I inherited a CSS stylesheet and in a few places it does things like:

margin:7px 0 0 0;
/margin-top:9px;

or

background: url(../images/list-hover.png) 0 0 no-repeat;
/background:url(../images/lists-hover.png) 0 2px no-repeat;

anyone know what that forward slash is doing?

回答1:

It's to target LTE IE7. This hack isn't known as much as the IE6 underscore one.

    #myelement {
background:red; /*Should show as red in all browsers, expect IE6 and IE7 because...*/
/background:yellow; /*IE7 should have yellow*/
_background:green; /*IE6 should have green*/
}

You can make the backslash almost anything you want really, expect the underscore _ as that will target IE6. I use the $ personally.

EDIT:
I've included the IE6 trick too there, as anything IE7 and below will take the / property unless you also have an _ property too.

To target IE8, IE7, and IE6 you need to have that order above.



标签: css css-hack