.tr…">
当前位置:首页 > CSS

用css制作火车图标

2026-04-01 00:39:22CSS

使用CSS制作火车图标

通过CSS的伪元素、边框和变换属性可以构建一个简易的火车图标。以下是具体实现方法:

用css制作火车图标

<div class="train"></div>
.train {
  width: 120px;
  height: 60px;
  background-color: #333;
  border-radius: 10px;
  position: relative;
  margin: 50px;
}

.train::before {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: #555;
  border-radius: 50%;
  top: 45px;
  left: 15px;
}

.train::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: #555;
  border-radius: 50%;
  top: 45px;
  right: 15px;
}

.train .window {
  position: absolute;
  width: 30px;
  height: 20px;
  background-color: #87CEEB;
  top: 15px;
  left: 20px;
}

.train .chimney {
  position: absolute;
  width: 10px;
  height: 20px;
  background-color: #222;
  top: -20px;
  right: 20px;
}

添加动画效果

让火车图标具有移动效果:

用css制作火车图标

.track {
  width: 300px;
  height: 5px;
  background-color: #666;
  position: relative;
}

.train {
  animation: moveTrain 3s linear infinite;
}

@keyframes moveTrain {
  0% { transform: translateX(0); }
  100% { transform: translateX(200px); }
}

更复杂的火车设计

构建包含多节车厢的火车:

<div class="locomotive"></div>
<div class="wagon"></div>
<div class="wagon"></div>
.locomotive, .wagon {
  width: 80px;
  height: 50px;
  background-color: #456;
  display: inline-block;
  position: relative;
  margin-right: -5px;
}

.locomotive {
  width: 100px;
  background-color: #234;
}

.locomotive::before, .wagon::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background-color: #333;
  border-radius: 50%;
  bottom: -10px;
}

.locomotive::before { left: 20px; }
.wagon::before { left: 15px; }

.locomotive::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 15px;
  background-color: #222;
  top: -15px;
  right: 20px;
}

这些CSS代码可以创建不同复杂度的火车图标,通过调整尺寸、颜色和位置参数可获得各种风格的火车视觉效果。

标签: 图标火车
分享给朋友:

相关文章

css 字体图标制作

css 字体图标制作

字体图标制作方法 使用字体文件(如TTF/OTF)转换为Web字体 下载或设计矢量图标,保存为TTF或OTF格式。通过在线工具(如Fontello、IcoMoon)将字体转换为Web字体格式(WOF…

vue实现图标跳动

vue实现图标跳动

实现图标跳动的几种方法 在Vue中实现图标跳动效果可以通过CSS动画、第三方动画库或JavaScript动态控制样式。以下是几种常见实现方式: CSS关键帧动画 通过@keyframes定义跳动动画…

图标css制作

图标css制作

使用CSS制作图标的方法 内联SVG结合CSS 将SVG代码直接嵌入HTML,通过CSS控制样式和动画: <svg class="icon" viewBox="0 0 24 24">…

uniapp图标事件

uniapp图标事件

添加图标事件的方法 在UniApp中,可以通过@click或其他事件绑定方法为图标添加交互功能。以下以<uni-icons>组件为例: <uni-icons type="conta…

vue实现图标拖拽

vue实现图标拖拽

Vue实现图标拖拽的基本方法 使用Vue实现图标拖拽功能可以通过HTML5的拖放API结合Vue的事件绑定来实现。以下是基本实现步骤: <template> <div…

css3 图标制作

css3 图标制作

使用CSS3制作图标的方法 纯CSS绘制基础形状 通过CSS的border、transform、box-shadow等属性组合可创建简单图标。例如绘制三角形: .triangle { width…