用CSS或SVG画半圈

par*_*ent 6 css svg css3 css-shapes

我正在寻找一种使用CSS或SVG绘制圆圈底部的方法.我已经看到了这个答案,但它处理的是一个完美的半圈,而我需要一个额外的段来切断它使它不到一半.使用纯CSS可能无法实现,但SVG的答案对我来说很难修改.

<svg class="pie">
  <circle cx="115" cy="115" r="110"></circle>
  <path d="M115,115 L115,5 A110,110 1 0,1 225,115 z"></path>
</svg>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Wea*_*.py 17

为什么不使用patharc命令使用两个元素?

<svg width="135" height="135">
  <path d="M125,85 a60,60 0 1,0 -115,0" fill="#E79A16" /><!--Top Half-->
  <path d="M10,85 a60,60 0 0,0 115,0" fill="#D78500" /><!--Bottom Half-->
</svg>
Run Code Online (Sandbox Code Playgroud)


你可以轻松地分开它们.

<svg width="135" height="135">
  <path d="M125,80 a60,60 0 1,0 -115,0" fill="#E79A16" /><!--Top Half-->
</svg>
<svg width="135" height="135">
  <path d="M10,80 a60,60 0 0,0 115,0" fill="#D78500" /><!--Bottom Half-->
</svg>
<svg width="135" height="135">
  <path d="M10,0 a60,60 0 0,0 115,0" fill="#D78500" /><!--Bottom Half-->
</svg>
Run Code Online (Sandbox Code Playgroud)



小智 12

更简单的方法,无需使用path

<svg version="1.1" width="64" height="64" xmlns="http://www.w3.org/2000/svg">
    <clipPath id="cut-off">
        <rect x="0" y="0" width="64" height="40"/>
    </clipPath>

    <circle cx="32" cy="32" r="32" fill="#d08807"/>
    <circle cx="32" cy="32" r="32" fill="#e19b22" clip-path="url(#cut-off)"/>
</svg>
Run Code Online (Sandbox Code Playgroud)


Ori*_*iol 6

你可以用CSS做到这一点:

.partial-circle {
  position: relative;
  height: 20px;
  width: 100px;
  overflow: hidden;
}
.partial-circle:before {
  content: '';
  position: absolute;
  height: 100px;
  width: 100px;
  border-radius: 50%;
  bottom: 0;
  background: #D08707;
}
Run Code Online (Sandbox Code Playgroud)
<div class="partial-circle"></div>
Run Code Online (Sandbox Code Playgroud)

您还可以拥有这两部分:

.partial-circle {
  position: relative;
  width: 100px;
  overflow: hidden;
}
.partial-circle:before {
  content: '';
  position: absolute;
  height: 100px;
  width: 100px;
  border-radius: 50%;
}
.partial-circle.top {
  height: 80px;
}
.partial-circle.bottom {
  height: 20px;
}
.partial-circle.top:before {
  top: 0;
  background: #E19B21;
}
.partial-circle.bottom:before {
  bottom: 0;
  background: #D08707;
}
Run Code Online (Sandbox Code Playgroud)
<div class="partial-circle top"></div>
<div class="partial-circle bottom"></div>
Run Code Online (Sandbox Code Playgroud)