前端必学的CSS3波浪效果演示

news2025/7/7 9:28:39

目录

文章目录

前言

CSS3波浪效果

1.Html构建

2.CSS编写

3.完整代码

index.html文件

style.css文件

总结


前言

        随着前端技术的不断发展与进步,界面交互的样式要求和美感也越来越高,很多网页的交互都加上了css3动画,这里作者给大家分享一个前端开发必掌握的一个CSS3波浪效果,赶紧学起来吧,加在自己开发网页的底部,给页面增加一点活泼的气息~


CSS3波浪效果

        

        这是使用 SVG 和 CSS 动画制作的波浪效果,上半部分是蓝色(可修改成其他颜色)渐变的背景颜色,下半部分就是波浪,有四条波浪在不停的来回起伏,非常逼真。该波浪效果可用于大部分页面的底部,使页面增加一点活泼的气息。。

1.Html构建

代码如下(示例):

<div class="inner_header"> 填充蓝色(可修改成其他颜色)渐变的背景颜色
<div class="waves">这部分就是波浪的svg,有四条波浪在不停的来回起伏,效果非常逼真


		<div class="header">
			<div class="inner-header flex">
				<h1>简单的 CSS3 波浪效果</h1>
			</div>
			<div>
				<svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
					viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
					<defs>
						<path id="gentle-wave"
							d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
					</defs>
					<g class="parallax">
						<use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
						<use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
						<use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
						<use xlink:href="#gentle-wave" x="48" y="7" fill="#fff" />
					</g>
				</svg>
			</div>
		</div>

2.CSS编写

代码如下(示例):

这里通过CSS3animation动画属性来控制四条线条在不停的来回起伏,形成波浪效果



.header {
    position: relative;
    text-align: center;
    background: linear-gradient(60deg, rgba(84, 58, 183, 1) 0%, rgba(0, 172, 193, 1) 100%);
/* 	background: #FFAFBD;  
	background: -webkit-linear-gradient(to right, #ffc3a0, #FFAFBD);  
	background: linear-gradient(to right, #ffc3a0, #FFAFBD); 
 */
    color: white;
}


.inner-header {
    height: 65vh;
    width: 100%;
    margin: 0;
    padding: 0;
}



.waves {
    position: relative;
    width: 100%;
    height: 15vh;
    margin-bottom: -7px; /*Fix for safari gap*/
    min-height: 100px;
    max-height: 150px;
}

.content {
    position: relative;
    height: 20vh;
    text-align: center;
    background-color: white;
}

.content a {
    margin: 0 5px;
    font-size: 12px;
    color: #333;
}

.content a:hover {
    color: #000;
}

/* Animation */

.parallax > use {
    animation: move-forever 25s cubic-bezier(0.55, 0.5, 0.45, 0.5) infinite;
}
.parallax > use:nth-child(1) {
    animation-delay: -2s;
    animation-duration: 7s;
}
.parallax > use:nth-child(2) {
    animation-delay: -3s;
    animation-duration: 10s;
}
.parallax > use:nth-child(3) {
    animation-delay: -4s;
    animation-duration: 13s;
}
.parallax > use:nth-child(4) {
    animation-delay: -5s;
    animation-duration: 20s;
}
@keyframes move-forever {
    0% {
        transform: translate3d(-90px, 0, 0);
    }
    100% {
        transform: translate3d(85px, 0, 0);
    }
}
/*Shrinking for mobile*/
@media (max-width: 768px) {
    .waves {
        height: 40px;
        min-height: 40px;
    }
    .content {
        height: 30vh;
    }
    h1 {
        font-size: 24px;
    }
}

3.完整代码

index.html文件

<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8" />
		<title>简单的CSS3波浪效果演示_dowebok</title>
		<link rel="stylesheet" href="style.css" />
	</head>
	<body>
		<div class="header">
			<div class="inner-header flex">
				<h1>简单的 CSS3 波浪效果</h1>
			</div>
			
			<div>
				<svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
					viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
					<defs>
						<path id="gentle-wave"
							d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
					</defs>
					<g class="parallax">
						<use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
						<use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
						<use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
						<use xlink:href="#gentle-wave" x="48" y="7" fill="#fff" />
					</g>
				</svg>
			</div>
		</div>


	</body>
</html>

style.css文件

body {
    margin: 0;
}

h1 {
    font-family: 'Lato', sans-serif;
    font-weight: 300;
    letter-spacing: 2px;
    font-size: 48px;
}
p {
    font-family: 'Lato', sans-serif;
    letter-spacing: 1px;
    font-size: 14px;
    color: #333333;
}

.header {
    position: relative;
    text-align: center;
    background: linear-gradient(60deg, rgba(84, 58, 183, 1) 0%, rgba(0, 172, 193, 1) 100%);
/* 	background: #FFAFBD;  
	background: -webkit-linear-gradient(to right, #ffc3a0, #FFAFBD);  
	background: linear-gradient(to right, #ffc3a0, #FFAFBD); 
 */
    color: white;
}
.logo {
    width: 50px;
    fill: white;
    padding-right: 15px;
    display: inline-block;
    vertical-align: middle;
}

.inner-header {
    height: 65vh;
    width: 100%;
    margin: 0;
    padding: 0;
}

.flex {
    /*Flexbox for containers*/
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.waves {
    position: relative;
    width: 100%;
    height: 15vh;
    margin-bottom: -7px; /*Fix for safari gap*/
    min-height: 100px;
    max-height: 150px;
}

.content {
    position: relative;
    height: 20vh;
    text-align: center;
    background-color: white;
}

.content a {
    margin: 0 5px;
    font-size: 12px;
    color: #333;
}

.content a:hover {
    color: #000;
}

/* Animation */

.parallax > use {
    animation: move-forever 25s cubic-bezier(0.55, 0.5, 0.45, 0.5) infinite;
}
.parallax > use:nth-child(1) {
    animation-delay: -2s;
    animation-duration: 7s;
}
.parallax > use:nth-child(2) {
    animation-delay: -3s;
    animation-duration: 10s;
}
.parallax > use:nth-child(3) {
    animation-delay: -4s;
    animation-duration: 13s;
}
.parallax > use:nth-child(4) {
    animation-delay: -5s;
    animation-duration: 20s;
}
@keyframes move-forever {
    0% {
        transform: translate3d(-90px, 0, 0);
    }
    100% {
        transform: translate3d(85px, 0, 0);
    }
}
/*Shrinking for mobile*/
@media (max-width: 768px) {
    .waves {
        height: 40px;
        min-height: 40px;
    }
    .content {
        height: 30vh;
    }
    h1 {
        font-size: 24px;
    }
}

总结

        以上就是今天要讲的内容啦,给大家分享了一个css3波浪效果,谢谢观看,如果觉得对您有帮助的话,可否给博主一个小小的赞和关注~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/405494.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

vue路由配置

1、路由的使用 一、安装路由 npm i vue-router 二、配置路由 在根目录下创建文件夹router&#xff0c;在router文件夹下创建index.js文件&#xff0c;如下图所示 在index.js文件中写入如下代码&#xff0c;实现创建一个路由器 import VueRouter from "vue-router&qu…

Object.defineproperty方法(详解)

Object.defineproperty 的作用就是直接在一个对象上定义一个新属性&#xff0c;或者修改一个已经存在的属性 Object.defineproperty可以接收三个参数 Object.defineproperty(obj, prop, desc) obj : 第一个参数就是要在哪个对象身上添加或者修改属性 prop : 第二个参数就是…

HTML网站导航栏的制作

一、导航条的制作 &#xff08;1&#xff09;代码图 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"viewport…

photo-sphere-viewer中文文档

photo-sphere-viewer中文文档安装插件Configuration 配置项Standard options 常规配置container (required)adapter 适配器panorama (required)plugins 插件caption 标题size 全景图宽度高度markers 标注navbar 导航栏minFovmaxFovdefaultZoomLvlfisheyedefaultLongdefaultLatl…

vue+element-ui前端使用print-js实现打印,可自定义样式(横纵向,缩放比,字体大小,背景色)

vueelement-ui前端使用print-js实现打印下载依赖使用print-js实现打印功能需要打印的内容按钮调用打印函数打印函数设置默认打印横纵向&#xff08;IE不生效&#xff09;设置默认打印缩放比调整打印字体大小自定义字体大小生效自定义背景颜色生效参数print-js官网链接: https:/…

vue 3 项目实战一(绘制登录界面)

目录 一、概述 二、创建vue项目 三、需求分析 四、构建组件 五、vue组件之间的通信 一、概述 本文记录了项目实现的详细步骤以及原理&#xff0c;十分适合初学vue的萌新练手&#xff0c;也是阶段性学习的一个总结&#xff0c;可能会有些啰嗦&#xff0c;勿怪~。 先从登录…

PostMan——安装使用教程(图文详解)

为了验证接口能否被正常访问&#xff0c;我们常常需要使用测试工具&#xff0c;来对数据接口进行检测。 好处&#xff1a;接口测试工具能让我们在不写任何代码的情况下&#xff0c;对接口进行调用和调试。 下载并安装PostMan 首先&#xff0c;下载并安装PostMan&#xff0c;请…

若依管理系统RuoYi-Vue(前后端分离版)项目启动教程

RuoYi-Vue 是一个 Java EE 企业级快速开发平台&#xff0c;基于经典技术组合&#xff08;Spring Boot、Spring Security、MyBatis、Jwt、Vue&#xff09;&#xff0c;内置模块如&#xff1a;部门管理、角色用户、菜单及按钮授权、数据权限、系统参数、日志管理、代码生成等。在…

【Vue】Axios详解

文章目录1 Axios简介1.1 什么是Axios?1.2 Axios的特性2 Axios的使用2.1 Axios的安装2.2 Axios的创建2.2.1 Proxy配置代理2.2.1.1 核心代码2.2.1.2 代码解释2.2.1.3 多个跨域2.2.2 Axios的二次封装2.2.2.1 为什么要二次封装2.2.2.2 Axios实例化2.2.2.2.1 引入2.2.2.2.2 创建axi…

前端面试题八股文汇总(最新)

文章目录一 、第一回合1.开发中遇到的困难&#xff1f;2. Css的盒子模型3. Pull和fetch的区别4. SPA单页面项目5.SEO优化6.BOM浏览器对象模型7.数组、对象、字符串中的一些方法8.解构赋值9...args剩余参数(扩展运算符)10.arguments 对象11. Promise以及底层封装12.浅拷贝深拷贝…

【node进阶】一文带你快速入门koa框架

✅ 作者简介&#xff1a;一名普通本科大三的学生&#xff0c;致力于提高前端开发能力 ✨ 个人主页&#xff1a;前端小白在前进的主页 &#x1f525; 系列专栏 &#xff1a; node.js学习专栏 ⭐️ 个人社区 : 个人交流社区 &#x1f340; 学习格言: ☀️ 打不倒你的会使你更强&a…

Vue基础知识总结 11:前端路由vue-router

&#x1f345; 作者简介&#xff1a;哪吒&#xff0c;CSDN2021博客之星亚军&#x1f3c6;、新星计划导师✌、博客专家&#x1f4aa; &#x1f345; 哪吒多年工作总结&#xff1a;Java学习路线总结&#xff0c;搬砖工逆袭Java架构师 &#x1f345; 关注公众号【哪吒编程】&#…

vue自适应布局(各种浏览器,分辨率)

1.前言 spa页面的layout布局对于前端项目的影响至关重要&#xff0c;在我们进行web端开发的时候&#xff0c;前端的各种大小屏幕&#xff0c;各种内核的浏览器不同&#xff0c;会导致我们的页面呈现出不一样的效果&#xff0c;如何进行更好的取舍&#xff0c;怎么能够达到产品…

使用Nginx部署Vue+SpringBoot前后端分离项目(超详细!)

目录 一、前后端环境准备 1、前端环境准备 2、后端环境准备 二、前后端打包 1、前端打包 2、后端打包 三、服务器前后端配置及部署 1、前端配置 安装nginx 创建项目目录 前端项目部署 2、后端配置 安装宝塔 安装mysql 使用本地Navicat连接远程数据库 安装jdk环境…

echarts文档解读

前言&#xff1a;今天给大家分享一个前端的开源可视化图标库echarts。 &#x1f495;点击下方名片&#xff0c;即可领取学长个人微信&#x1f495; echarts 全局 echarts 对象&#xff0c;在 script 标签引入 echarts.js 文件后获得&#xff0c;或者在 AMD 环境中通过 require…

Vue 插槽(slot)详细介绍(对比版本变化,避免踩坑)

目录 前言 正文 插槽是什么&#xff1f; 怎么使用插槽&#xff1f; 基本用法 后备&#xff08;默认&#xff09;内容 具名插槽 作用域插槽 插槽版本变化 总结 前言 Vue中的插槽&#xff08;slot&#xff09;在项目中用的也是比较多的&#xff0c;今天就来介绍一下插…

npm install 提示Unable to authenticate, need: BASIC realm=“Sonatype Nexus Repository Manager“

场景&#xff1a; 执行npm install时提示Unable to authenticate Password: Email: (this IS public) xxqq.com Logged in as uploader on http://192.168.xx.xxx:8074/repository/npm-internal/. PS D:\GitworkspaceUi\gisquest-cloud-ui-workcenter> npm install npm ERR…

【登录界面】vue、element-ui登录界面模板

vue、element-ui登录界面模板这里总结一个用vue、element-ui写的登录界面&#xff0c;为以后复制粘贴备用。 截图 代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>登录</title><!--…

vue-quill-editor富文本编辑器使用步骤

首先放上效果图 目录 1.安装 2.引入到项目中 3.在页面上写组件 4.配置option 5.给工具栏鼠标悬停加上中文释义 6.上传图片到七牛云 7.自定义控制图片大小 1.安装 npm install vue-quill-editor -S2.引入到项目中 有两种挂载方式&#xff1a; 全局挂载 和 在组件中挂载&…

【Vue插槽详解】

Vue插槽详解Vue插槽的作用一、默认插槽完整代码&#xff1a;二、具名插槽完整代码&#xff1a;三、作用域插槽完整代码如下&#xff1a;Vue插槽的作用 Vue插槽是Vue中常见的一种组件间的相互通信方式&#xff0c;作用是让父组件可以向子组件指定位置插入html结构&#xff0c;适…