Как сделать дуги с помощью CSS3?

Я пытаюсь добиться следующего взгляда с чистым css:

enter image description here

Где каждая белая дуга - это другой элемент, скажем, span. Я знаю, что мы можем создавать круглые формы с помощью css, но как его можно превратить в форму дуги?

Ответ 1

В следующем HTML:

<div id="arcs">
    <div>
        <div>
            <div>
                <div></div>
            </div>
        </div>
    </div>
</div>

И CSS:

#arcs div {
    border: 2px solid #000; /* the 'strokes' of the arc */
    display: inline-block;
    min-width: 4em; /* the width of the innermost element */
    min-height: 4em; /* the height of the innermost element */
    padding: 0.5em; /* the spacing between each arc */
    border-radius: 50%; /* for making the elements 'round' */
    border-top-color: transparent; /* hiding the top border */
    border-bottom-color: transparent;
}

#arcs div {
  border: 2px solid #000;
  /* the 'strokes' of the arc */
  display: inline-block;
  min-width: 4em;
  /* the width of the innermost element */
  min-height: 4em;
  /* the height of the innermost element */
  padding: 0.5em;
  /* the spacing between each arc */
  border-radius: 50%;
  /* for making the elements 'round' */
  border-top-color: transparent;
  /* hiding the top border */
  border-bottom-color: transparent;
}
<div id="arcs">
  <div>
    <div>
      <div>
        <div></div>
      </div>
    </div>
  </div>
</div>

Ответ 2

Подход SVG:

Я бы рекомендовал использовать SVG для рисования таких форм:

В приведенном ниже примере я использовал элемент SVG path для рисования дуги. Этот элемент принимает один атрибут d для описания структуры фигуры. d атрибуты принимают несколько команд и соответствующие необходимые параметры.

Я использовал только 2 команды:

  • Команда
  • M используется для перемещения пера в определенную точку. Эта команда принимает 2 параметра x и y, и обычно наш путь начинается с этой команды. Это в основном определяет отправную точку нашего рисунка.
  • A, которая используется для рисования кривых и дуг. Эти команды принимают 7 параметров для рисования дуги/кривой. Подробное объяснение этой команды Здесь.

Скриншот:

Изображение, показывающее дуги

Полезные ресурсы:

Рабочий пример:

svg {
  width: 33%;
  height: auto;
}
<svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">

  <defs>
    <g id="arcs" fill="none" stroke="#fcfcfc">
      <path d="M80,80 A100,100,0, 0,0 80,220" stroke-width="4" />
      <path d="M90,90 A85,85,0, 0,0 90,210" stroke-width="3.5" />
      <path d="M100,100 A70,70,0, 0,0 100,200" stroke-width="3" />
      <path d="M110,110 A55,55,0, 0,0 110,190" stroke-width="2.5" />
    </g>
  </defs>
  
  <rect x="0" y="0" width="300" height="300" fill="#373737" />

  <use xlink:href="#arcs" />
  <use xlink:href="#arcs" transform="translate(300,300) rotate(180)" />
  
</svg>