html - 在CSS中绘制半圆形

标签 html css css-shapes

我正在尝试复制形状

enter image description here

当我在 CSS 中使用圆形时,它看起来有些不同:

.shape{
  display: inline-block;
  text-align: center;
  line-height: 18px;
  border-radius: 9px 9px 9px 9px;
  color: #000000;
  padding-left: 6px;
  padding-right: 6px;
  font-weight: bold;
  font-family: sans-serif;
}
.shape.orange{
  background-color: #FF931B;
}
<span class="shape orange">CC6</span>

如何获得正确的形状?

最佳答案

这可以使用 radial-gradient

.shape{
  display: inline-block;
  font-size:50px;
  line-height:1.5em;
  padding:0 0.4em;
  font-weight: bold;
  font-family: sans-serif;
  background: 
    radial-gradient(100% 50% at right, #FF931B 98%,transparent 100%) left,
    radial-gradient(100% 50% at left , #FF931B 98%,transparent 100%) right,
    #FF931B content-box; /*Don't color the padding to keep it for radial-gradient*/
  background-size:0.4em 100%; /* Width same as padding and height 100%*/
  background-repeat:no-repeat;
}
<span class="shape">CC6</span>
<span class="shape" style="font-size:70px">CC6</span>
<span class="shape" style="font-size:15px">CC6</span>

或者使用 border-radius 如下:

.shape{
  display: inline-block;
  font-size:50px;
  line-height:1.5em;
  padding:0 0.4em;
  font-weight: bold;
  font-family: sans-serif;
  background:  #FF931B;
  border-radius:0.4em/50%;
}
<span class="shape">CC6</span>
<span class="shape" style="font-size:70px">CC6</span>
<span class="shape" style="font-size:15px">CC6</span>

CSS Semi rounded shape

关于html - 在CSS中绘制半圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58758097/

相关文章:

html - 页脚与内容 div 重叠

javascript - 在 HTML Canvas 中包含文本

jquery - 分割具有 3D 厚度效果的背景图像

html - 带有渐变颜色的圆形边框

html - 如何在 CSS 中塑造边框尖峰

html - 如何在html表格内创建虚线边框线

python - 元素有时出现有时不出现,如何继续脚本?

html - <div> 关闭后仍然有效

php - 使用 Colspan 时,最后一列的右边界消失

javascript - 有什么办法可以实时改变元素的宽度?