How to check if css value is supported by the browser?

前端 未结 6 1458
温柔的废话
温柔的废话 2020-12-14 17:06

Im not very skilled in javascript so please be bear with me. Safari 6 and below and older android mobile browsers and maybe more do not support the css value VH. My DIV#id o

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 17:36

    There is the new API CSS.supports. Supported in most browsers except IE.

    console.log(
      // CSS.supports(property, value)
      1, CSS.supports("text-decoration-style", "blink"),
      2, CSS.supports("display", "flex"),
      3, CSS.supports('--foo', 'red'),
      4, CSS.supports('(--foo: red)'),
    
      // CSS.supports(DOMstring)
      5, CSS.supports("( transform-origin: 5% 5% )"),
      6, CSS.supports("( transform-style: preserve ) or ( -moz-transform-style: preserve ) or " 
      + "( -o-transform-style: preserve ) or ( -webkit-transform-style: preserve )")
    )

    And there is a similar feature in CSS, the @supports feature query selector, also supported in most browsers except IE:

    @supports (display: grid) {
      div {
        display: grid;
      }
    }
    @supports not (display: grid) {
      div {
        float: right;
      }
    }
    

提交回复
热议问题