Ordering in vendor based CSS3 Vs Standard CSS3 syntax

后端 未结 3 922
北海茫月
北海茫月 2020-12-06 03:19

In order to achieve cross-browser compatibility, we tend to use both vendor specific extensions and standard CSS3 syntax. I know CSS3 is still in draft, but we have alre

相关标签:
3条回答
  • 2020-12-06 03:26

    Now, this tries standard syntax first and then falls back to browser based extension.

    This may be a misleading statement. A compliant browser will try the standard unprefixed property first, but if it also supports the prefixed property in addition to the standard, then it will apply that prefix as well. This usually results in the standard declaration being overridden by the prefixed declaration and a browser's potentially non-standard implementation of that property, defeating the purpose of having the standard property there in the first place.

    The reason why you should declare the unprefixed property last is because that's how properties cascade in a rule: a browser will always use the last applicable one. Prefixed and unprefixed versions of a property are treated as the same property with respect to the cascade, so you want a browser to do its best to adhere to the standards when applying that property.1

    If a browser implements a prefix but not the standard, that's fine, but if it implements both, you want to ensure it uses the standard instead. You do this by declaring the standard property last.


    1 As far as I'm aware this is not dictated by the spec, because as far as the spec is concerned vendor extensions are non-standard and so their implementation cannot be described. Although the syntax of vendor prefixes is described in the spec, implementations are left entirely up to the discretion of vendors.

    However it's an agreed-upon convention by most browser developers when implementing prefixed versions of a to-be-standardized property or rule, to always treat both prefixed and unprefixed versions as aliases of each other.

    0 讨论(0)
  • 2020-12-06 03:27

    When writing CSS3 properties, the modern wisdom is to list the "real" property last and the vendor prefixes first.

    Another thing to think about when you do include the non-prefixed property is to put it after the vendor-prefixed versions. When a browser implements the standard version of a property, as specified in the relevant CSS3 specification, you most likely want it to use that implementation instead of the experimental, browser-specific version (which it will likely still support to be backwards-compatible). Putting it last should ensure that it will override the vendor-prefixed implementation.

    See Ordering CSS3 Properties

    See also : Remember non-vendor-prefixed CSS 3 properties (and put them last)

    0 讨论(0)
  • 2020-12-06 03:44

    The order of prefixes doesn't matter, as long as you keep the future standard version as last.

    If a browser drops support for the prefix, it will simply ignore the rule and execute the standard version.

    ps: same as A.K. but simpler, so you don't have to read all pages.

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