Chip
Chip

Reputation: 81

CSS clip-path not working in Safari with children/pseudo elements

I got a pretty basic SVG clip-path:

<svg width="0" height="0">
  <defs>
    <clipPath id="line">
      <path d="..." />
    </clipPath>
  </defs>
</svg>

Which i wanna use w/ CSS:

div {
  clip-path: url(#line);

  &:before {
    ...
  }
}

It's working fine with Google Chrome, but not showing at all in Safari.
Also tried adding the -webkit- prefix.
Here's a live demo: https://jsfiddle.net/1dtpLg8y/
Its actually working if you get rid of the :before element: https://jsfiddle.net/fp5mouLn/
Here's a working SVG only version: https://jsfiddle.net/3gt67cLh/1/ but would love to do this with CSS.

Expected outcome:
enter image description here

Not showing anything in Safari.

Upvotes: 2

Views: 3144

Answers (2)

user3561869
user3561869

Reputation: 63

If herrstrietzel's solution does not work, try "filter: hue-rotate(0deg);"

I had a similar problem, and adding "overflow:hidden" did not work, but adding "filter: hue-rotate(0deg)" did.

Upvotes: 1

herrstrietzel
herrstrietzel

Reputation: 17165

Adding overflow:hidden to your line div seems to solve this issue.

(tested on iOs safari)

.line {
  -webkit-clip-path: url(#line);
  clip-path: url(#line);
  background-color: #ccc;
  width: 196px;
  height: 6px;
  position: relative;
  overflow: hidden;
}
.line:before {
  content: "";
  width: 80px;
  height: 80px;
  background: radial-gradient(red, transparent 35%);
  position: absolute;
  left: -30px;
  top: -36px;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
<div class="line"></div>

<svg width="0" height="0">
  <defs>
    <clipPath id="line">
      <path
        fillRule="evenodd"
        clipRule="evenodd"
        d="M0 5C0 4.65482 0.279822 4.375 0.625 4.375H5C8 4 9.11049 0.375 10 0.375C11 0.375 12 4 15 4.375H195.375C195.72 4.375 196 4.65482 196 5V5C196 5.34518 195.72 5.625 195.375 5.625H15C12 5.5 10 1.8 10 1.8C10 1.8 8 5.5 5 5.625H0.625C0.279822 5.625 0 5.34518 0 5V5Z"
        fill="black"
      />
    </clipPath>
  </defs>
</svg>

Upvotes: 3

Related Questions