Do double forward slashes direct IE to use specific css?

前端 未结 2 1715
你的背包
你的背包 2020-12-07 02:27

I have just found something very weird while developing a website. While trying to get a div element to display across the top of the screen, I noticed that I wasn\'t achiev

相关标签:
2条回答
  • 2020-12-07 03:07

    // is not a valid CSS comment.

    Browsers that parse CSS properly will ignore //position because //position is not a valid property name (details are here, property -> IDENT S* -> follow it through).

    This only works in IE7 due to its well known bug of accepting properties with junk prepended to them.

    It's not just // that works. IE7 will have red text here:

    body {
        !/!*//color: red;
    }
    

    This is most typically exploited with *, for example *display: inline; as part of the display: inline-block workaround for IE7.

    0 讨论(0)
  • 2020-12-07 03:07

    Don't fall into the temptation of commenting out single lines or blocks and not using the correct /* */ couple. A customer who has access to the website folder just chose by himself to comment out a single line using this:

    //*  comment here   *//
    

    Actually, Chrome and Safari will ignore ANYTHING that follows this line. I would call it a "css killer". :D

    0 讨论(0)
提交回复
热议问题