css полукруглый круг с прозрачными формами на нем - PullRequest
1 голос
/ 26 апреля 2020

Мне нужен круг с половиной границы снизу, я хочу заполнить этот круг цветом в процентах.

Мне нужно наложить еще один круг, но в центре другого круга есть прозрачные фигуры.

Сначала мне нужен круг с половиной рамки, а затем наложить на него еще один круг с прозрачными формами

Есть ли более простой способ, например, с помощью canvas?

Что я нужно: enter image description here

    .circle {
      width: 80px;
      height: 80px;
      margin-left: 0;
      border: 1px solid #E0E0E0;
      border-radius: 100%;
      background-color: transparent;
      display: -webkit-box;
      display: -moz-box;
      display: -ms-flexbox;
      display: -webkit-flex;
      display: flex;
      -webkit-align-items: center;
      -moz-align-items: center;
      -ms-align-items: center;
      align-items: center;
    }
    .example {
       background: linear-gradient(transparent 20%, #00EFAF 20%);
    }
 <div class="circle example" data-fill="50">
    </div>

1 Ответ

2 голосов
/ 26 апреля 2020

Вы можете использовать маску в сочетании с градиентом для достижения этого:

.box {
  --b: 10px; /* 10px of visible border */

  width:150px;
  height:150px;
  display:inline-block;
  border-radius:50%;
  background:linear-gradient(transparent calc(100% - var(--fill)),#00EFAF 0);
  -webkit-mask:radial-gradient(farthest-side,transparent calc(99.5% - var(--b)),#fff calc(100% - var(--b)));
          mask:radial-gradient(farthest-side,transparent calc(99.5% - var(--b)),#fff calc(100% - var(--b)));
}

body {
  background:#f2f2f2;
}
<div class="box" style="--fill:20%"></div>
<div class="box" style="--fill:50%;--b:20px;"></div>
<div class="box" style="--fill:80%;--b:5px;"></div>

CSS half bordered circle

Используйте его как псевдоэлемент для легкого добавления содержимого внутри:

.box {
  --b: 10px; /* 10px of visible border */

  width:150px;
  height:150px;
  display:inline-flex;
  justify-content:center;
  align-items: center;
  font-size:30px;
  border-radius:50%;
  overflow:hidden;
  position:relative;
  z-index:0;
}

.box:before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  background:linear-gradient(transparent calc(100% - var(--fill)),#00EFAF 0);
  -webkit-mask:radial-gradient(farthest-side,transparent calc(99.5% - var(--b)),#fff calc(100% - var(--b)));
          mask:radial-gradient(farthest-side,transparent calc(99.5% - var(--b)),#fff calc(100% - var(--b)));
}

body {
  background:#f2f2f2;
}
<div class="box" style="--fill:20%">20%</div>
<div class="box" style="--fill:50%;--b:20px;">50%</div>
<div class="box" style="--fill:80%;--b:5px;">80%</div>

CSS circle with gradient border

Если вы хотите выполнить анимацию, вы можете настроить линейный градиент, как показано ниже

.box {
  --b: 10px; /* 10px of visible border */

  width:150px;
  height:150px;
  display:inline-flex;
  justify-content:center;
  align-items: center;
  font-size:30px;
  border-radius:50%;
  overflow:hidden;
  position:relative;
  z-index:0;
}

.box:before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  background:linear-gradient(#00EFAF,#00EFAF) content-box;
  padding-top:calc(100% - var(--fill));
  transition:0.5s;
  -webkit-mask:radial-gradient(farthest-side,transparent calc(99.5% - var(--b)),#fff calc(100% - var(--b)));
          mask:radial-gradient(farthest-side,transparent calc(99.5% - var(--b)),#fff calc(100% - var(--b)));
}

.box:hover::before {
  padding-top:0%;
}

body {
  background:#f2f2f2;
}
<div class="box" style="--fill:20%">20%</div>
<div class="box" style="--fill:50%;--b:20px;">50%</div>
<div class="box" style="--fill:80%;--b:5px;">80%</div>

Вот еще одна идея, использующая clip-path

.box {
  width:150px;
  height:150px;
  display:inline-flex;
  justify-content:center;
  align-items: center;
  font-size:30px;
  overflow:hidden;
  position:relative;
  z-index:0;
}
.box::before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  border:var(--b,10px) solid #00EFAF;
  border-radius:50%;
  clip-path:
    polygon(0   calc(100% - var(--fill)),
           100% calc(100% - var(--fill)),
           100% 100%,
           0    100%);
  transition:0.5s;
}
.box:hover::before {
  clip-path:
    polygon(0   0,
           100% 0,
           100% 100%,
           0    100%);

}
body {
  background:#f2f2f2;
}
<div class="box" style="--fill:20%">20%</div>
<div class="box" style="--fill:50%;--b:20px;">50%</div>
<div class="box" style="--fill:80%;--b:5px;">80%</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...