当前位置:首页 > CSS

css制作圆环

2026-01-28 08:39:16CSS

使用 border-radius 和 border 属性

通过设置元素的 border-radius 为 50% 使其变为圆形,再通过 border 属性调整边框宽度和颜色即可形成圆环。

.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 10px solid #3498db;
  background-color: transparent;
}

使用伪元素实现渐变圆环

结合伪元素和 border 属性可以创建更复杂的圆环效果,例如渐变颜色的圆环。

.gradient-circle {
  width: 100px;
  height: 100px;
  position: relative;
  border-radius: 50%;
  background-color: transparent;
}

.gradient-circle::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  border-radius: 50%;
  border: 10px solid transparent;
  border-top-color: #3498db;
  border-bottom-color: #e74c3c;
  animation: rotate 2s linear infinite;
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

使用 SVG 绘制圆环

SVG 提供更灵活的圆环绘制方式,适合需要动态调整的场景。

<svg width="100" height="100" viewBox="0 0 100 100">
  <circle cx="50" cy="50" r="40" fill="none" stroke="#3498db" stroke-width="10" />
</svg>

使用 CSS conic-gradient

通过 conic-gradient 可以创建彩色圆环,适合数据可视化场景。

.conic-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: conic-gradient(
    #3498db 0% 25%,
    #e74c3c 25% 50%,
    #f1c40f 50% 75%,
    #2ecc71 75% 100%
  );
  mask: radial-gradient(transparent 35px, #000 36px);
}

使用 clip-path 裁剪

通过 clip-path 裁剪出环形区域,适合不规则圆环设计。

.clip-circle {
  width: 100px;
  height: 100px;
  background-color: #3498db;
  clip-path: circle(40px at center);
  position: relative;
}

.clip-circle::after {
  content: '';
  position: absolute;
  width: 60px;
  height: 60px;
  background-color: white;
  border-radius: 50%;
  top: 20px;
  left: 20px;
}

css制作圆环

标签: 圆环css
分享给朋友:

相关文章

react 如何引入css

react 如何引入css

在 React 中引入 CSS 的方法 React 提供了多种引入 CSS 的方式,可以根据项目需求选择合适的方法。以下是常见的几种方式: 内联样式 内联样式直接在组件中通过 style 属性定义,…

css制作

css制作

CSS 基础语法 CSS(层叠样式表)用于控制网页的样式和布局。其基本语法由选择器和声明块组成。选择器指定要样式化的HTML元素,声明块包含一个或多个属性-值对,用花括号 {} 包裹。 select…

css如何制作圆

css如何制作圆

使用 border-radius 属性制作圆 通过设置 border-radius 属性为元素添加圆角效果。当 border-radius 的值等于元素宽度和高度的一半时,元素会呈现圆形。 .cir…

css表格制作

css表格制作

CSS 表格制作基础 使用 CSS 可以创建美观且响应式的表格。以下是一些基本方法: table 元素用于定义表格,tr 定义行,td 定义单元格,th 定义表头单元格。 <table>…

css制作圆形

css制作圆形

使用 border-radius 属性 通过设置 border-radius 为 50%,可以将元素变为圆形。元素的宽度和高度需相同,否则会呈现椭圆形。 .circle { widt…

表格制作css

表格制作css

基础表格样式 使用CSS可以轻松地为HTML表格添加样式。以下是一个基础表格的HTML和CSS示例: <table class="basic-table"> <thead&g…