如何在css中将圆的一部分设置为背景

Mad*_*ari 3 css sass css3 css-shapes

我试图将圆圈的一部分作为背景

我想要的是 :

在此输入图像描述

例:

在此输入图像描述

在此输入图像描述

在此输入图像描述

我试图通过border-radius它,但它总是不起作用.

这是我尝试过的:

a{
  min-width: 80px;
  height: 60px;
  padding: 20px 15px !important;

  // active/current navigation link
  &.active, &:hover{
     background-color: #e15669;
    &:before{
      position: absolute;
      content: '';
      display: block;
      height: 60px;
      width: 30px;
      border-radius: 90px 0 0 90px;
      -moz-border-radius: 90px 0 0 90px;
      -webkit-border-radius: 90px 0 0 90px;
      background: #e15669;
      top: 0;
      left: -30px;
      z-index: -1;
    }
    &:after {
      position: absolute;
      content: '';
      display: block;
      height: 60px;
      width: 30px;
      border-radius: 0 90px 90px 0;
      -moz-border-radius: 0 90px 90px 0;
      -webkit-border-radius: 0 90px 90px 0;
      background: #e15669;
      top: 0;
      right: -30px;
      z-index: -1;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Pau*_*e_D 8

使用径向渐变为背景着色

body {
  text-align: center;
}
a {
  padding: 1em;
  display: inline-block;
  text-decoration: none;
  margin: 2em;
  color: white;
  background: radial-gradient(circle farthest-side, red, red 90%, transparent 90%);
}
Run Code Online (Sandbox Code Playgroud)
<a href="#1">RANDOM</a>

<a href="#2">RANDOM TEXT</a>

<a href="#3">TEXT</a
Run Code Online (Sandbox Code Playgroud)

替代解决方案

定位的伪元素.这允许容易地转换背景.

body {
  text-align: center;
}
a {
  padding: 1em;
  display: inline-block;
  text-decoration: none;
  margin: 2em;
  color: white;
  position: relative; /* positioning context */
  overflow: hidden; /* required to clip circle */
}
a::before {
  content: '';
  position: absolute; /* doesn't affect other elements */
  top: 50%; /* set 50% down */
  transform: translateY(-50%); /* pull up 50% of own height */
  width: 100%;
  left: 0;
  background: green;
  padding-bottom: 100%; /* makes square */
  border-radius: 50%; /* round it off */
  z-index: -1;
  transition:background .35s ease;
}

 a:hover::before {
   background: blue;
 }
Run Code Online (Sandbox Code Playgroud)
<a href="#1">RANDOM</a>

<a href="#2">RANDOM TEXT</a>

<a href="#3">TEXT</a>
Run Code Online (Sandbox Code Playgroud)