分享:CSS3用transition实现边框动画效果

来源:互联网 发布:图片归类整理软件 编辑:程序博客网 时间:2024/06/01 13:50

废话不多说,直接上代码:

1:css

code:

  1. /*** css code ***/
  2. .animate{transition: all 0.5s ease-in-out;}
  3. .m{width: 200px;height: 50px;text-align: center;font-size: 20px;line-height: 50px;font-family: Microsoft Yahei; color: gray;border:2px solid #dfdfdf;cursor: pointer;}
  4. .b{position: relative;}
  5. .b span{display: inline-block;position: absolute;content: none;border: 0;width: 0;height: 0;}
  6. .b span.top{right:0;top:0;border-top:2px solid #000;margin-top:-2px;}
  7. .b:hover span.top{width:198px;}
  8. .b span.right{right:0;bottom:0;border-right:2px solid #000;margin-right:-2px;}
  9. .b:hover span.right{height:48px;}
  10. .b span.bottom{left:0;bottom:0;border-bottom:2px solid #000;margin-bottom:-2px;}
  11. .b:hover span.bottom{width:198px;}
  12. .b span.left{left:0;top:0;border-left:2px solid #000;margin-left:-2px;}
  13. .b:hover span.left{height:48px;}

2:HTML

code:

  1. <div style="width: 90%;height: 100px;">
  2. <div class="m b">
  3. ABOUT US
  4. <span class="top animate"></span>
  5. <span class="right animate"></span>
  6. <span class="bottom animate"></span>
  7. <span class="left animate"></span>
  8. </div>
  9. </div>