Search code examples
csscss-shapes

Complex CSS Shape


I need some CSS help. It’s hard to explain, but looking at the snippet I need the black part without the red.

I used two elements, but it should be possible with one...

.q-rounder {
  background: #222;
  width: 15px;
  height: 15px;
}

.quarter-circle {
  width: 15px;
  height: 15px;
  background: red;
  border-radius: 100px 0 0 0;
  -moz-border-radius: 100px 0 0 0;
  -webkit-border-radius: 100px 0 0 0;
}
<div class="q-rounder">
  <div class="quarter-circle"></div>
</div>

(fiddle)


Solution

  • Use a radial gradient as background

    .q-rounder {
      background: 
        radial-gradient(farthest-side at bottom right,transparent 94%, #222);
      width: 15px;
      height: 15px;
    }
    <div class="q-rounder">
    </div>

    Another syntax with the at to have better support (safari doesn't support the at)

    .q-rounder {
      background: 
        radial-gradient(farthest-side,transparent 94%, #222) top left/200% 200%;
      width: 15px;
      height: 15px;
    }
    <div class="q-rounder">
    </div>