其他分享
首页 > 其他分享> > 每日CSS_霓虹灯按钮悬停效果

每日CSS_霓虹灯按钮悬停效果

作者:互联网

每日CSS_霓虹灯按钮悬停效果

2020_12_20

霓虹灯按钮


1. 代码解析

1.1 html 代码片段解析

		<a href="#">
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			霓虹灯 按钮
		</a>

这四个 span 标签用来模拟上下左右四根线


1.2 CSS 代码片段解析


2. 源码如下

  1. html

    <!DOCTYPE html>
    <html>
     <head>
      <meta charset="utf-8">
      <title></title>
      <link rel="stylesheet" href="2020_12_20.css">
     </head>
     <body>
      <a href="#">
       <span></span>
       <span></span>
       <span></span>
       <span></span>
       霓虹灯 按钮
      </a>
     </body>
    </html>
    
  2. css

    body{
      margin: 0;
      padding: 0;
      /* flex 布局 */
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      background: #031321;
      font-family: 华文琥珀;
    }
    a{
      /* 为绝对定位做参考点 */
      position: relative;
      display: inline-block;
      /* 将文字与线分割开 */
      padding: 15px 30px;
      color: #2196f3;
      /* 文字间隔 */
      letter-spacing: 4px;
      text-decoration: none;
      font-size: 24px;
      overflow: hidden;
      /* 附在 a 上的动画, 触发时和回退时均有效 */
      transition: 0.2s;
    }
    a:hover{
      color: #255784;
      background: #2196f3;
      /* 多个阴影模拟霓虹灯 */
      box-shadow:
              0 0 10px #2196f3,0 0 40px #2196f3,0 0 10px #2196f3,0 0 80px #2196f3;
      /* 有延迟 */
      transition-delay: 1s;
    }
    a span{
      position: absolute;
      display: block;
    }
    a span:nth-child(1){
       top: 0;
       left: -100%;
       width: 100%;
       height: 2px;
       background: linear-gradient(90deg, transparent, #2196f3);
     }
    a:hover span:nth-child(1){
      left: -100%;
      transition: 1s;
    }
    a span:nth-child(3){
       bottom: 0;
       left: 100%;
       width: 100%;
       height: 2px;
       background: linear-gradient(270deg, transparent, #2196f3);
     }
    a:hover span:nth-child(3){
      left: -100%;
      transition: 1s .5s;
    }
    a span:nth-child(2){
      right: 0;
      top: -100%;
      width: 2px;
      height: 100%;
      background: linear-gradient(180deg, transparent, #2196f3);
    }
    a:hover span:nth-child(2){
      top: 100%;
      transition: 1s .25s;
    }
    a span:nth-child(4){
      left: 0;
      top: 100%;
      width: 2px;
      height: 100%;
      background: linear-gradient(360deg, transparent, #2196f3);
    }
    a:hover span:nth-child(4){
      top: -100%;
      transition: 1s .75s;
    }
    

标签:span,2196f3,100%,霓虹灯,nth,background,child,悬停,CSS
来源: https://www.cnblogs.com/xiaxiangx/p/14164984.html