企业网站定制开发前端必学的CSS3波浪效果演示

目录


前言

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


CSS3波浪效果

        

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

1.Html构建

代码如下(示例):

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

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

2.CSS编写

代码如下(示例):

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

  1. .header {
  2. position: relative;
  3. text-align: center;
  4. background: linear-gradient(60deg, rgba(84, 58, 183, 1) 0%, rgba(0, 172, 193, 1) 100%);
  5. /* background: #FFAFBD;
  6. background: -webkit-linear-gradient(to right, #ffc3a0, #FFAFBD);
  7. background: linear-gradient(to right, #ffc3a0, #FFAFBD);
  8. */
  9. color: white;
  10. }
  11. .inner-header {
  12. height: 65vh;
  13. width: 100%;
  14. margin: 0;
  15. padding: 0;
  16. }
  17. .waves {
  18. position: relative;
  19. width: 100%;
  20. height: 15vh;
  21. margin-bottom: -7px; /*Fix for safari gap*/
  22. min-height: 100px;
  23. max-height: 150px;
  24. }
  25. .content {
  26. position: relative;
  27. height: 20vh;
  28. text-align: center;
  29. background-color: white;
  30. }
  31. .content a {
  32. margin: 0 5px;
  33. font-size: 12px;
  34. color: #333;
  35. }
  36. .content a:hover {
  37. color: #000;
  38. }
  39. /* Animation */
  40. .parallax > use {
  41. animation: move-forever 25s cubic-bezier(0.55, 0.5, 0.45, 0.5) infinite;
  42. }
  43. .parallax > use:nth-child(1) {
  44. animation-delay: -2s;
  45. animation-duration: 7s;
  46. }
  47. .parallax > use:nth-child(2) {
  48. animation-delay: -3s;
  49. animation-duration: 10s;
  50. }
  51. .parallax > use:nth-child(3) {
  52. animation-delay: -4s;
  53. animation-duration: 13s;
  54. }
  55. .parallax > use:nth-child(4) {
  56. animation-delay: -5s;
  57. animation-duration: 20s;
  58. }
  59. @keyframes move-forever {
  60. 0% {
  61. transform: translate3d(-90px, 0, 0);
  62. }
  63. 100% {
  64. transform: translate3d(85px, 0, 0);
  65. }
  66. }
  67. /*Shrinking for mobile*/
  68. @media (max-width: 768px) {
  69. .waves {
  70. height: 40px;
  71. min-height: 40px;
  72. }
  73. .content {
  74. height: 30vh;
  75. }
  76. h1 {
  77. font-size: 24px;
  78. }
  79. }

3.完整代码

index.html文件

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

style.css文件

  1. body {
  2. margin: 0;
  3. }
  4. h1 {
  5. font-family: 'Lato', sans-serif;
  6. font-weight: 300;
  7. letter-spacing: 2px;
  8. font-size: 48px;
  9. }
  10. p {
  11. font-family: 'Lato', sans-serif;
  12. letter-spacing: 1px;
  13. font-size: 14px;
  14. color: #333333;
  15. }
  16. .header {
  17. position: relative;
  18. text-align: center;
  19. background: linear-gradient(60deg, rgba(84, 58, 183, 1) 0%, rgba(0, 172, 193, 1) 100%);
  20. /* background: #FFAFBD;
  21. background: -webkit-linear-gradient(to right, #ffc3a0, #FFAFBD);
  22. background: linear-gradient(to right, #ffc3a0, #FFAFBD);
  23. */
  24. color: white;
  25. }
  26. .logo {
  27. width: 50px;
  28. fill: white;
  29. padding-right: 15px;
  30. display: inline-block;
  31. vertical-align: middle;
  32. }
  33. .inner-header {
  34. height: 65vh;
  35. width: 100%;
  36. margin: 0;
  37. padding: 0;
  38. }
  39. .flex {
  40. /*Flexbox for containers*/
  41. display: flex;
  42. justify-content: center;
  43. align-items: center;
  44. text-align: center;
  45. }
  46. .waves {
  47. position: relative;
  48. width: 100%;
  49. height: 15vh;
  50. margin-bottom: -7px; /*Fix for safari gap*/
  51. min-height: 100px;
  52. max-height: 150px;
  53. }
  54. .content {
  55. position: relative;
  56. height: 20vh;
  57. text-align: center;
  58. background-color: white;
  59. }
  60. .content a {
  61. margin: 0 5px;
  62. font-size: 12px;
  63. color: #333;
  64. }
  65. .content a:hover {
  66. color: #000;
  67. }
  68. /* Animation */
  69. .parallax > use {
  70. animation: move-forever 25s cubic-bezier(0.55, 0.5, 0.45, 0.5) infinite;
  71. }
  72. .parallax > use:nth-child(1) {
  73. animation-delay: -2s;
  74. animation-duration: 7s;
  75. }
  76. .parallax > use:nth-child(2) {
  77. animation-delay: -3s;
  78. animation-duration: 10s;
  79. }
  80. .parallax > use:nth-child(3) {
  81. animation-delay: -4s;
  82. animation-duration: 13s;
  83. }
  84. .parallax > use:nth-child(4) {
  85. animation-delay: -5s;
  86. animation-duration: 20s;
  87. }
  88. @keyframes move-forever {
  89. 0% {
  90. transform: translate3d(-90px, 0, 0);
  91. }
  92. 100% {
  93. transform: translate3d(85px, 0, 0);
  94. }
  95. }
  96. /*Shrinking for mobile*/
  97. @media (max-width: 768px) {
  98. .waves {
  99. height: 40px;
  100. min-height: 40px;
  101. }
  102. .content {
  103. height: 30vh;
  104. }
  105. h1 {
  106. font-size: 24px;
  107. }
  108. }

总结

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

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发