Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to scale `clip-path: path`?

Tags:

css

svg

clip-path

I have a clip-path, which cuts a certain shape of. The problem is that it is set in absolute coordinates. If I put % there it breaks. How to scale it so that it fits the canvas borders and is stretched together with canvas?

.canvas {
    width: 200px;
    height: 200px;
    background-color: black;
}

.clip {
    width: 100%;
    height: 100%;

    background-color: orange;
    content: "";
    clip-path: path('M 100 50 A 75 75 0 0 1 0 50 A 75 75 0 0 1 100 50 z');
 }
<div class="canvas"><div class="clip">sadf</div></div>
like image 318
klm123 Avatar asked Mar 27 '26 11:03

klm123


1 Answers

You can use another svg and add clipPathUnits="objectBoundingBox" to it

More info here

.canvas {
  width: 200px;
  height: 200px;
  background-color: black;
}

.clip {
  width: 100%;
  height: 100%;
  background-color: orange;
  clip-path: url(#path);
}
<svg height="0" width="0">
  <defs>
    <clipPath id="path"  clipPathUnits="objectBoundingBox">
      <path d="M 0,0.5
           Q 0.50,0.15 1,0.50
           Q 0.50,0.85 0,0.50">
      </path>
    </clipPath>
  </defs>
</svg>
<div class="canvas">
  <div class="clip">sadf</div>
</div>
like image 96
Charles Lavalard Avatar answered Apr 01 '26 07:04

Charles Lavalard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!