Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clip-Path Inset in CSS not working in chrome

I'm trying to use the CSS property clip-path, but I get an Invalid property value error in Chrome.

screenshot

Here's a small demo:

.clip-me {  
  clip-path: inset(0px 50px 50px 0px); /* top, right, bottom, left */
}
<img class="clip-me" src="http://i.stack.imgur.com/MnWjF.png" width="100">

Clip Path Example

Note: This is different from this question on clip-path does not work with chrome, because it's specifically asking about how to apply clip path using SVG (not CSS)

According to Can I Use, it should work in chrome.

like image 395
KyleMit Avatar asked Feb 18 '15 16:02

KyleMit


People also ask

How do you clip content in CSS?

The <top> , <right> , <bottom> , and <left> values may be either a <length> or auto . If any side's value is auto , the element is clipped to that side's inside border edge. The element does not clip (default). This is different from rect(auto, auto, auto, auto) , which clips to the element's inside border edges.

What is clip path inset?

The clip-path CSS property creates a clipping region that sets what part of an element should be shown. Parts that are inside the region are shown, while those outside are hidden.

Can I use SVG clip path?

Support for clip-path in SVG is supported in all browsers with basic SVG support.


1 Answers

Turns out I just needed the -webkit- prefix (although I don't see it in this list of vendor prefixes)

.clip-me {           /* top, right, bottom, left */
  -webkit-clip-path: inset(0px 50px 50px 0px); 
          clip-path: inset(0px 50px 50px 0px); 
}
<img class="clip-me" src="http://i.stack.imgur.com/MnWjF.png" width="100">

Update as of Chrome 55, clip-path without the vendor prefix is now supported, but many other browsers still require using -webkit-clip-path so it's safer to include it for now.

Here's a snapshot of CanIUse (as of 2017), with the additional details in the top right corner of partial support browsers often indicating the need for the -webkit- prefix

Can I Use Snaptshot

Further Reading:

  • Clipping in CSS and SVG — The clip-path Property and <clipPath> Element
  • Using clip-path
like image 60
KyleMit Avatar answered Sep 29 '22 16:09

KyleMit