文字悬停下划线动画效果集合

栏目: Html · 发布时间: 5年前

核心属性

box-sizing: border-box 使所有元素的尺寸计算变为传统模型

line-height: 200px 设置元素的高度为200px,并且文字垂直居中显示

text-decoration: none 去除a标签默认的下划线

:before + :hover/:focus + visibility + transform 自定义下划线的悬停动画效果

box-shadow 发光的下划线

:hover/:focus + animation + height + transform + opacity 悬停下划线变背景的动画效果

  1. <div class="container">
  2. <h2>
  3. <a href=''>把鼠标放到这里</a>
  4. </h2>
  5. <h2 class='uno'>
  6. <a href=''>再放一下</a>
  7. </h2>
  8. <h2 class='dos bis'>
  9. <a href=''>发光的下划线I</a>
  10. </h2>
  11. <h2 class='dos'>
  12. <a href=''>发光的下划线II</a>
  13. </h2>
  14. <h3 class='tres'>
  15. <a href=''>悬停的动画效果</a>
  16. </h3>
  17. </div>
  1. *, *:after, *:before {
  2. box-sizing: border-box;
  3. }
  4. * {
  5. margin: 0;
  6. padding: 0;
  7. border: 0 none;
  8. position: relative;
  9. outline: none;
  10. }
  11. html, body {
  12. background: #004050;
  13. font-weight: 300;
  14. width: 100%;
  15. }
  16. h2, h3 {
  17. background: #0D757D;
  18. width: 100%;
  19. min-height: 200px;
  20. line-height: 200px;
  21. font-size: 3rem;
  22. font-weight: normal;
  23. text-align: center;
  24. color: rgba(0,0,0,.4);
  25. margin: 3rem auto 0;
  26. }
  27. .uno {
  28. background: #ff5e33;
  29. }
  30. .dos.bis {
  31. background: #85144B;
  32. }
  33. .dos {
  34. background: #FADD40;
  35. }
  36. h3 {
  37. background: #2B5B89;
  38. }
  39. h2 > a, h3 > a {
  40. text-decoration: none;
  41. color: rgba(0,0,0,.4);
  42. z-index: 1;
  43. }
  44. h2 > a:before {
  45. content: "";
  46. position: absolute;
  47. width: 100%;
  48. height: 3px;
  49. bottom: 0;
  50. left: 0;
  51. background: #9CF5A6;
  52. visibility: hidden;
  53. border-radius: 5px;
  54. transform: scaleX(0);
  55. transition: .25s linear;
  56. }
  57. h2 > a:hover:before,
  58. h2 > a:focus:before {
  59. visibility: visible;
  60. transform: scaleX(1);
  61. }
  62. .uno a:before {
  63. background: rgba(0,0,0,0);
  64. box-shadow: 0 0 10px 2px #ffdb00;
  65. }
  66. .dos > a:after {
  67. content: "";
  68. position: absolute;
  69. width: 100%;
  70. height: 7px;
  71. border: 1px solid #000;
  72. bottom: -2px;
  73. left: 0;
  74. background: #fff;
  75. border-radius: 5px;
  76. opacity: 0;
  77. transform: scalex(0);
  78. transition: .5s;
  79. }
  80. .dos.bis > a:after {
  81. opacity: .05;
  82. transform: scalex(1);
  83. }
  84. .dos:hover > a:after {
  85. opacity: .15;
  86. transform: scalex(1);
  87. }
  88. .dos.bis > a:before {
  89. background: rgba(0,0,0,0);
  90. box-shadow: 0 0 10px 2px #FADD40;
  91. }
  92. .dos > a:before {
  93. background: rgba(0,0,0,0);
  94. box-shadow: 0 0 10px 2px #FF5E33;
  95. }
  96. h3 > a:before {
  97. content: "";
  98. background: #7FDBFF;
  99. position: absolute;
  100. width: 100%;
  101. height: 5px;
  102. bottom: 0;
  103. left: 0;
  104. border-radius: 5px;
  105. transform: scaleX(0);
  106. animation: 1.4s forwards no-hover-v linear;
  107. animation-fill-mode: forwards;
  108. z-index: -1;
  109. }
  110. h3 > a:hover:before,
  111. h3 > a:focus:before {
  112. animation: .5s forwards hover-v linear;
  113. animation-fill-mode: forwards;
  114. }
  115. @keyframes hover-v {
  116. 0% {
  117. transform: scaleX(0);
  118. height: 5px;
  119. }
  120. 45% {
  121. transform: scaleX(1.05);
  122. height: 5px;
  123. }
  124. 55% { height: 5px; }
  125. 100% {
  126. transform: scaleX(1.05);
  127. height: 3.8rem;
  128. }
  129. }
  130. @keyframes no-hover-v {
  131. 0% {
  132. transform: scaleX(1.05);
  133. height: 3.8rem;
  134. }
  135. 45% { height: 5px; }
  136. 55% {
  137. transform: scaleX(1.05);
  138. height: 5px;
  139. opacity: 1;
  140. }
  141. 100% {
  142. transform: scaleX(0);
  143. height: 5px;
  144. opacity: .02;
  145. }
  146. }

以上所述就是小编给大家介绍的《文字悬停下划线动画效果集合》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Just My Type

Just My Type

Simon Garfield / Profile Books / 2010-10-21 / GBP 14.99

What's your type? Suddenly everyone's obsessed with fonts. Whether you're enraged by Ikea's Verdanagate, want to know what the Beach Boys have in common with easy Jet or why it's okay to like Comic Sa......一起来看看 《Just My Type》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器