CSS: *html #id_name

后端 未结 2 1445
庸人自扰
庸人自扰 2021-01-17 04:42

I have this code

*html #alertBox {
    height:100px;
}

#modalContainer > #alertBox {
    position:fixed;
}

is this supported by css, i

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-17 05:03

    *html #alertBox {
        height:100px;
    }
    

    That's a mistyped star-HTML. Star-HTML is a CSS hack usually used to target rules at IE6.

    The star-HTML prefix in a rule shouldn't match anything, because there is no element (*) above the root element (html). But it does in IE up to version 6 due to bugs in that browser.

    However for this to be a valid rule, there must be a space between the * and the html. The current code is invalid CSS: the validator will complain and browsers might do unexpected things with it. As it happens, in the current crop of browsers there is no difference: IE6-7 allows the spaceless syntax, the others ignore the whole rule. But you shouldn't really rely on that.

    #modalContainer > #alertBox {
        position:fixed;
    }
    

    That's a child selector: it selects the alertBox when it's a direct child of modalContainer.

    > is something IE6 doesn't understand at all, so the consequence is to target the rule at all browsers except IE6 (which doesn't support position: fixed). This makes it more-or-less the opposite of the star-HTML hack. Clearly it is being used for the purpose here, as otherwise the selector, including two unique IDs, is quite redundant.

提交回复
热议问题