Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut a hole in a background gradient [duplicate]

Tags:

css

I would like to cut a hole into this element where the skyblue is so I can see the background. I cannot seem to figure out how to do this. I have seen it done but I cannot duplicate it using a conic-gradient.

This is what I have gotten so far. I have tried to make the skyblue transparent, but that just showed the conic-gradient.

.container { width: 200px; }
.spinner {
  height: 0px;
  width: 100%;
  padding-bottom: calc(100% - 20px);
  margin: 0;
  background: radial-gradient(circle at center, skyblue 54%, transparent 54.8%),
    conic-gradient(from 0deg at center, transparent 45deg, orange 360deg);
  clip-path: circle(46% at center);
}
<div class="container">
  <div class="spinner"></div>
</div>

I also tried using an :after pseudo selector, but that didn't work:

  .spinner:after {
    content: '';
    background: green;
    clip-path: circle(50px at center);
    width: 168px;
    height: 168px;
  }
like image 829
Get Off My Lawn Avatar asked Oct 15 '26 06:10

Get Off My Lawn


1 Answers

I was able to figure it out by adding mask-image.

body { background: purple; }
.container { width: 200px; }

.spinner {
  height: 0px;
  width: 100%;
  padding-bottom: calc(100% - 20px);
  margin: 0;
  background: conic-gradient(from 0deg at center, transparent 45deg, orange 360deg);
  clip-path: circle(46% at center);
  -webkit-mask-image: radial-gradient(circle at center, transparent 54%, black 54.8%);
  mask-image: radial-gradient(circle at center, transparent 54%, black 54.8%);
}
<div class="container">
  <div class="spinner"></div>
</div>
like image 150
Get Off My Lawn Avatar answered Oct 16 '26 19:10

Get Off My Lawn



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!