当前位置:首页 > CSS

css制作齿轮

2026-02-27 06:05:10CSS

使用CSS制作齿轮效果

通过CSS的伪元素和变换属性可以创建齿轮形状。以下是实现方法:

css制作齿轮

基础齿轮结构

.gear {
  width: 100px;
  height: 100px;
  background-color: #333;
  border-radius: 50%;
  position: relative;
}

添加齿轮齿

.gear::before {
  content: "";
  position: absolute;
  top: -15px;
  left: 25px;
  width: 50px;
  height: 30px;
  background-color: #333;
  border-radius: 5px;
}

.gear::after {
  content: "";
  position: absolute;
  top: 25px;
  left: -15px;
  width: 30px;
  height: 50px;
  background-color: #333;
  border-radius: 5px;
}

创建多个齿轮齿

使用旋转变换创建均匀分布的齿轮齿:

css制作齿轮

.gear {
  /* 基础样式 */
  width: 100px;
  height: 100px;
  background-color: #333;
  border-radius: 50%;
  position: relative;
}

.gear::before {
  content: "";
  position: absolute;
  width: 40px;
  height: 20px;
  background-color: #333;
  top: -10px;
  left: 30px;
  box-shadow: 
    0 70px 0 #333,
    70px 0 0 #333,
    0 -70px 0 #333,
    -70px 0 0 #333,
    50px 50px 0 #333,
    -50px 50px 0 #333,
    50px -50px 0 #333,
    -50px -50px 0 #333;
}

添加中心孔

.gear::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: #fff;
  border-radius: 50%;
  top: 35px;
  left: 35px;
}

动画效果

让齿轮旋转:

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

.gear {
  animation: rotate 5s linear infinite;
}

更复杂的齿轮

使用box-shadow创建更多齿:

.complex-gear {
  width: 150px;
  height: 150px;
  background: #555;
  border-radius: 50%;
  position: relative;
}

.complex-gear::before {
  content: "";
  position: absolute;
  width: 60px;
  height: 30px;
  background: #555;
  top: -15px;
  left: 45px;
  border-radius: 5px;
  box-shadow: 
    0 120px 0 #555,
    120px 0 0 #555,
    0 -120px 0 #555,
    -120px 0 0 #555,
    85px 85px 0 #555,
    -85px 85px 0 #555,
    85px -85px 0 #555,
    -85px -85px 0 #555;
}

这些CSS技术可以组合使用来创建各种齿轮效果,通过调整尺寸、颜色和阴影位置可以改变齿轮的外观。

标签: 齿轮css
分享给朋友:

相关文章

css制作标尺

css制作标尺

使用CSS制作标尺的方法 方法一:使用线性渐变和伪元素 通过CSS的线性渐变和伪元素可以创建水平或垂直标尺。以下是一个水平标尺的示例代码: .ruler { width: 100%; he…

css制作六边形

css制作六边形

使用CSS创建六边形的方法 通过CSS的clip-path属性可以轻松实现六边形效果。以下是一个基础示例: .hexagon { width: 100px; height: 55px;…

css怎么制作表格

css怎么制作表格

使用HTML和CSS创建表格 HTML提供<table>标签用于创建表格结构,结合CSS可以自定义样式。以下是基本实现方法: HTML结构 <table> <th…

怎么制作css文档

怎么制作css文档

创建CSS文档的基本步骤 新建一个纯文本文件,将文件后缀名改为.css,例如styles.css。使用代码编辑器(如VS Code、Sublime Text等)打开文件,开始编写CSS规则。 编写…

css制作圆弧

css制作圆弧

CSS 制作圆弧的方法 使用 border-radius 属性 通过 border-radius 可以轻松创建圆弧效果。该属性控制元素的圆角大小,值越大圆弧越明显。例如: .arc { wid…

css网页制作

css网页制作

CSS 网页制作基础 CSS(层叠样式表)用于控制网页的视觉呈现,包括布局、颜色、字体等。以下为关键知识点和实用方法: 基本语法结构 CSS 规则由选择器和声明块组成: 选择器 { 属性: 值…