Do custom CSS properties use one leading dash or two?

前端 未结 2 1470
心在旅途
心在旅途 2020-12-02 00:46
#elem {
  -myCustom: 99;
}

OR

#elem {
  --myCustom: 99;
}

I have seen both of the above used in examples online.

2条回答
  •  半阙折子戏
    2020-12-02 01:33

    • single leading dash is used for vendor prefixes
    • double leading dash is used for defining custom properties.

    2 Defining Custom Properties: the '--*' family of properties

    A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS), like --foo. The production corresponds to this: it’s defined as any valid identifier that starts with two dashes.

    An example from W3C:

    :root {
      --main-color: #06c;
      --accent-color: #006;
    }
    /* The rest of the CSS file */
    #foo h1 {
      color: var(--main-color);
    }
    

    It's worth noting that CSS variables are implemented in Firefox 31 and newer.

提交回复
热议问题