当前位置:首页 > 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
分享给朋友:

相关文章

react 如何引入css

react 如何引入css

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

css制作图片

css制作图片

CSS 制作图片的方法 使用 background-image 属性 通过 background-image 属性可以为元素设置背景图片。这种方法适用于将图片作为背景而非内容的一部分。 .eleme…

css精灵图制作

css精灵图制作

CSS 精灵图制作方法 准备工具 图像编辑软件(如 Photoshop、GIMP 或在线工具) CSS 代码编辑器 步骤 收集图像资源 将需要合并的小图标或图片整理到一个文件夹中,确保这些图片尺寸…

css制作二级菜单

css制作二级菜单

使用纯CSS制作二级菜单 通过CSS的:hover伪类和子选择器实现二级菜单的显示与隐藏。以下是一个典型的结构和样式示例: HTML结构 <nav class="menu"> &l…

表格制作css

表格制作css

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

css简历制作

css简历制作

使用CSS制作简历的基本方法 选择简洁的布局结构,单列或双列布局适合大多数简历。使用display: flex或display: grid实现响应式设计,确保在不同设备上显示良好。 字体选择上,标题…