当前位置:首页 > CSS

css线条特效制作

2026-03-12 08:50:36CSS

CSS线条特效制作方法

基础线条动画 使用borderbackground属性配合animation实现简单线条动态效果:

.line-effect {
  height: 2px;
  background: linear-gradient(90deg, transparent, #3498db, transparent);
  animation: shine 2s infinite;
}
@keyframes shine {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

悬停下划线扩展 创建鼠标悬停时扩展的下划线效果:

.hover-underline {
  position: relative;
}
.hover-underline::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: 0;
  left: 50%;
  background-color: #e74c3c;
  transition: width 0.3s ease, left 0.3s ease;
}
.hover-underline:hover::after {
  width: 100%;
  left: 0;
}

SVG线条动画 结合SVG实现更复杂的路径动画:

<svg class="svg-line" viewBox="0 0 100 2">
  <path d="M0 1 H100" stroke="#9b59b6" stroke-width="2" stroke-dasharray="100" stroke-dashoffset="100"/>
</svg>
.svg-line {
  width: 100%;
  height: 2px;
}
@keyframes dash {
  to { stroke-dashoffset: 0; }
}
.svg-line path {
  animation: dash 1.5s forwards;
}

多段线条组合 通过伪元素创建分段的装饰线条:

.decorative-line {
  position: relative;
  padding: 20px 0;
}
.decorative-line::before,
.decorative-line::after {
  content: '';
  position: absolute;
  height: 1px;
  width: 40%;
  background: linear-gradient(to right, transparent, #2ecc71);
}
.decorative-line::before {
  top: 0;
  left: 0;
}
.decorative-line::after {
  bottom: 0;
  right: 0;
}

3D立体线条效果 使用box-shadowtransform模拟3D效果:

.line-3d {
  height: 4px;
  background: #f39c12;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transform: perspective(100px) rotateX(10deg);
}

虚线动画 创建动态滚动的虚线效果:

.dashed-line {
  height: 2px;
  background: repeating-linear-gradient(90deg, #3498db, #3498db 10px, transparent 10px, transparent 20px);
  animation: scroll 1s linear infinite;
}
@keyframes scroll {
  0% { background-position: 0 0; }
  100% { background-position: 20px 0; }
}

线条加载指示器 制作进度指示动画:

css线条特效制作

.loader-line {
  height: 4px;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.loader-line::before {
  content: '';
  position: absolute;
  height: 100%;
  width: 50%;
  background: #3498db;
  animation: loading 2s ease-in-out infinite;
}
@keyframes loading {
  0% { left: -50%; }
  100% { left: 150%; }
}

分享给朋友:

相关文章

vue实现线条动画效果

vue实现线条动画效果

使用 SVG 和 CSS 实现线条动画 在 Vue 中实现线条动画可以通过 SVG 结合 CSS 或 JavaScript 动画库完成。SVG 的路径动画效果流畅且易于控制。 定义一个 SVG 路径…

css特效制作

css特效制作

CSS 特效制作方法 悬停动画效果 通过 :hover 伪类结合 transition 实现平滑过渡。例如按钮颜色渐变: .button { background-color: #3498d…

简单css特效制作

简单css特效制作

CSS 文字阴影效果 为文字添加阴影效果可以通过 text-shadow 属性实现。该属性接受水平偏移、垂直偏移、模糊半径和颜色值。 .text-shadow { text-shadow: 2p…

js实现线条

js实现线条

使用Canvas绘制线条 在JavaScript中,可以通过HTML5的Canvas API绘制线条。Canvas提供了一套丰富的绘图功能,包括绘制直线、曲线等。 const canvas = do…

css特效制作

css特效制作

CSS 特效制作方法 CSS 特效可以通过多种方式实现,以下是一些常见且实用的特效制作方法: 文字阴影效果 使用 text-shadow 属性为文字添加阴影效果,可以设置多个阴影层叠: .te…

css制作线条

css制作线条

使用 border 属性制作线条 通过 border 属性可以轻松创建各种线条。例如,设置 border-bottom 可以生成水平线条: .line { border-bottom: 1px…