当前位置:首页 > CSS

css制作灯光

2026-02-27 07:21:15CSS

使用CSS制作灯光效果

通过CSS的box-shadowfilter属性可以模拟灯光效果,适用于按钮、图标或背景元素的光照增强。

基础灯光效果(发光按钮)

.glow-button {
  background-color: #4CAF50;
  border: none;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
  transition: box-shadow 0.3s ease;
}

.glow-button:hover {
  box-shadow: 0 0 30px rgba(76, 175, 80, 0.9);
}

霓虹灯文字效果

结合text-shadow和动画实现闪烁霓虹灯:

css制作灯光

.neon-text {
  color: #fff;
  text-shadow: 
    0 0 5px #fff,
    0 0 10px #fff,
    0 0 20px #ff00de,
    0 0 40px #ff00de;
  animation: flicker 1.5s infinite alternate;
}

@keyframes flicker {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
    text-shadow: 
      0 0 5px #fff,
      0 0 10px #fff,
      0 0 20px #ff00de,
      0 0 40px #ff00de;
  }
  20%, 24%, 55% {
    text-shadow: none;
  }
}

聚光灯效果

使用径向渐变和混合模式创建聚焦光斑:

.spotlight {
  position: relative;
  height: 300px;
  background: #222;
}

.spotlight::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200px;
  height: 200px;
  background: radial-gradient(
    circle closest-side,
    rgba(255,255,255,0.8),
    transparent
  );
  transform: translate(-50%, -50%);
  mix-blend-mode: overlay;
}

悬停灯光追踪

通过CSS变量实现鼠标悬停时的动态光照:

css制作灯光

.light-track {
  --x: 50%;
  --y: 50%;
  position: relative;
  background: #333;
  height: 200px;
  overflow: hidden;
}

.light-track::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
    circle at var(--x) var(--y),
    rgba(255,255,255,0.3),
    transparent 60%
  );
  pointer-events: none;
}

.light-track:hover::after {
  background: radial-gradient(
    circle at var(--x) var(--y),
    rgba(255,255,255,0.6),
    transparent 60%
  );
}

JavaScript配合(可选):

document.querySelector('.light-track').addEventListener('mousemove', (e) => {
  const rect = e.target.getBoundingClientRect();
  e.target.style.setProperty('--x', `${e.clientX - rect.left}px`);
  e.target.style.setProperty('--y', `${e.clientY - rect.top}px`);
});

3D灯泡效果

结合多重阴影和过渡创建立体灯泡:

.light-bulb {
  width: 80px;
  height: 80px;
  background: #f5f5f5;
  border-radius: 50%;
  position: relative;
  box-shadow: 
    inset 0 -5px 20px rgba(0,0,0,0.1),
    inset 0 10px 30px rgba(255,255,255,0.8),
    0 0 0 5px rgba(255,255,255,0.1),
    0 5px 20px rgba(255,200,0,0.3);
  transition: all 0.3s ease;
}

.light-bulb::after {
  content: "";
  position: absolute;
  top: 15%;
  left: 15%;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: radial-gradient(circle at center, #fff, transparent 60%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.light-bulb.on {
  box-shadow: 
    inset 0 -5px 20px rgba(0,0,0,0.1),
    inset 0 10px 30px rgba(255,255,255,0.8),
    0 0 0 5px rgba(255,255,255,0.1),
    0 5px 50px rgba(255,200,0,0.8);
}

.light-bulb.on::after {
  opacity: 0.6;
}

标签: 灯光css
分享给朋友:

相关文章

react 如何引入css

react 如何引入css

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

css制作三角形

css制作三角形

使用 border 属性创建三角形 通过设置元素的 border 属性可以实现三角形效果。原理是利用边框的交界处形成的斜边。 .triangle { width: 0; height: 0;…

css 制作石头

css 制作石头

使用CSS制作石头效果 通过CSS的border-radius、box-shadow和background属性可以模拟石头的自然外观。以下是一个简单实现: <div class="stone"…

css制作响应网页

css制作响应网页

响应式网页设计基础 使用CSS制作响应式网页的核心是让页面能够根据不同设备的屏幕尺寸自动调整布局和样式。主要通过媒体查询(Media Queries)、弹性布局(Flexbox)和网格布局(Grid)…

css制作卷边效果

css制作卷边效果

使用伪元素和渐变实现卷边效果 通过CSS伪元素和线性渐变可以模拟纸张卷边的视觉效果。这种方法不需要额外元素,仅通过::before或::after伪元素实现。 .element { positi…

div css制作

div css制作

使用 DIV 和 CSS 制作网页布局 DIV 是 HTML 中的块级元素,结合 CSS 可以灵活地创建各种网页布局。以下是常见的使用方法: 基础 DIV 结构 <div class="c…