Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Browser support for Background-clip: text?

Tags:

javascript

css

How would you test the value of background-clip: text, webkit supports text, but mozilla and other browsers do not I have tried modernizr teststyles but no luck

like image 415
Lawrence Avatar asked Jul 12 '12 13:07

Lawrence


2 Answers

var testEl = document.createElement( "x-test" );
var supportsWebkitBackgroundClipText = typeof testEl.style.webkitBackgroundClip !== "undefined" && ( testEl.style.webkitBackgroundClip = "text", testEl.style.webkitBackgroundClip === "text" );
like image 145
Inkbug Avatar answered Nov 14 '22 22:11

Inkbug


You can use @supports CSS at-rule:

As an example:

.colorful {
  color: #0098db;
}

@supports (background-clip: text) or (-webkit-background-clip: text) {
  .colorful {
    background: #0098db;
    background: linear-gradient(
      0deg,
      #0098db 0%,
      #0098db 45%,
      #c9d9ec 45%,
      #c9d9ec 100%
    );
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}
like image 30
pau.moreno Avatar answered Nov 14 '22 21:11

pau.moreno