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

css制作冒泡

2026-03-11 16:15:43CSS

使用CSS制作冒泡效果

冒泡效果可以通过CSS动画和伪元素实现,以下是一种常见的实现方式:

css制作冒泡

<div class="bubble"></div>
.bubble {
  width: 50px;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  position: relative;
  animation: float 3s ease-in-out infinite;
}

.bubble::before {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  background-color: rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  top: 10px;
  left: 10px;
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(-100px) rotate(20deg);
    opacity: 0;
  }
}

创建多个随机冒泡

要实现更自然的冒泡效果,可以创建多个随机大小和速度的冒泡:

css制作冒泡

<div class="bubbles-container">
  <div class="bubble"></div>
  <div class="bubble"></div>
  <div class="bubble"></div>
</div>
.bubbles-container {
  position: relative;
  height: 200px;
  overflow: hidden;
}

.bubble {
  position: absolute;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: float linear infinite;
}

/* 为每个气泡设置不同的大小和动画 */
.bubble:nth-child(1) {
  width: 20px;
  height: 20px;
  left: 10%;
  animation-duration: 4s;
}

.bubble:nth-child(2) {
  width: 35px;
  height: 35px;
  left: 40%;
  animation-duration: 6s;
}

.bubble:nth-child(3) {
  width: 15px;
  height: 15px;
  left: 70%;
  animation-duration: 5s;
}

@keyframes float {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-200px) scale(0.5);
    opacity: 0;
  }
}

添加交互效果的冒泡

可以使用CSS hover伪类为冒泡添加交互效果:

.bubble:hover {
  transform: scale(1.2);
  background-color: rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;
}

使用CSS变量控制冒泡样式

通过CSS变量可以更方便地控制冒泡的整体样式:

:root {
  --bubble-color: rgba(255, 255, 255, 0.6);
  --bubble-size: 30px;
  --float-distance: 150px;
}

.bubble {
  width: var(--bubble-size);
  height: var(--bubble-size);
  background-color: var(--bubble-color);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  to {
    transform: translateY(calc(-1 * var(--float-distance)));
  }
}

标签: css
分享给朋友:

相关文章

css字体制作

css字体制作

CSS字体设置基础 在CSS中设置字体主要通过font-family属性实现,可以指定多个字体作为备选。系统会优先使用第一个可用字体。 body { font-family: "Helvetic…

淘宝导航css制作

淘宝导航css制作

淘宝导航CSS制作 淘宝导航栏通常包含多个层级,包括主导航、子导航等。以下是实现类似淘宝导航栏的CSS制作方法。 基础HTML结构 <div class="nav-container">…

网页制作中css中运行

网页制作中css中运行

CSS 动画基础 CSS 动画通过 @keyframes 和 animation 属性实现动态效果。@keyframes 定义动画关键帧,animation 控制动画的持续时间、速度曲线等。 定…

div css制作

div css制作

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

css精灵图制作

css精灵图制作

CSS精灵图制作方法 将多个小图标或背景图像合并到一张大图中,通过CSS的background-position属性定位显示特定部分,减少HTTP请求次数,提升页面加载性能。 准备素材 收集需要合并…

纯css制作幻灯片

纯css制作幻灯片

纯CSS制作幻灯片的方法 关键思路 利用CSS动画和@keyframes实现自动轮播效果,通过隐藏其他幻灯片项并控制透明度或位置变化来切换内容。 基础HTML结构 <div class…