HTML CSS 液体填充效果
液体填充文字动画可以使用CSS | ::before选择器。使用关键帧设置动画每一帧的高度。最主要的是关键帧。对于上半部分的百分比,增加高度,而对于下半部分百分比,减小高度。使用25%作为高度的最小值。可以使用百分比值来更改,以根据需要更改动画的最小和最大高度以及外观。创建将在其中应用液体填充效果的文本。要创建结构,将需要标准的HTML。

HTML代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1.0" />
  7. <title>用HTML和CSS在文本上如何创建液体填充动画效果</title>
  8. </head>
  9. <body>
  10. <center>
  11. <h1>Fcant</h1>
  12. </center>
  13. </body>
  14. </html>

CSS代码

  1. <style>
  2. body {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. h1 {
  7. margin: 200px 0;
  8. padding: 0;
  9. font-size: 80px;
  10. position: relative;
  11. color:green;
  12. }
  13. h1:before {
  14. content: "Fcant";
  15. position: absolute;
  16. top: 0;
  17. left: 0;
  18. width: 100%;
  19. height: 100%;
  20. color:white;
  21. overflow: hidden;
  22. animation: animate 6s infinite;
  23. }
  24. @keyframes animate {
  25. 0% {
  26. height: 25%;
  27. }
  28. 25% {
  29. height: 50%;
  30. }
  31. 50% {
  32. height: 65%;
  33. }
  34. 75% {
  35. height: 40%;
  36. }
  37. 100% {
  38. height: 25%;
  39. }
  40. }
  41. </style>

实现填充效果的完整代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content=
  6. "width=device-width, initial-scale=1.0" />
  7. <title>
  8. 用HTML和CSS在文本上如何创建液体填充动画效果?
  9. </title>
  10. <style>
  11. body {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. h1 {
  16. margin: 200px 0;
  17. padding: 0;
  18. font-size: 80px;
  19. position: relative;
  20. color:green;
  21. }
  22. h1:before {
  23. content: "Fcant";
  24. position: absolute;
  25. top: 0;
  26. left: 0;
  27. width: 100%;
  28. height: 100%;
  29. color:white;
  30. overflow: hidden;
  31. animation: animate 6s infinite;
  32. }
  33. @keyframes animate {
  34. 0% {
  35. height: 25%;
  36. }
  37. 25% {
  38. height: 50%;
  39. }
  40. 50% {
  41. height: 65%;
  42. }
  43. 75% {
  44. height: 40%;
  45. }
  46. 100% {
  47. height: 25%;
  48. }
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <center>
  54. <h1>Fcant</h1>
  55. </center>
  56. </body>
  57. </html>

实现的效果

35.gif