html – 使用CSS仅旋转边框[复制]

前端之家收集整理的这篇文章主要介绍了html – 使用CSS仅旋转边框[复制]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这个问题与以下内容完全相同:> CSS Animated Circles – Stop center content from rotating1个
我正在尝试使用css仅旋转边框,但字体图标也在旋转.如何停止图标的旋转并仅使边框?

CSS:

  1. .circle {
  2. width: 100px;
  3. height: 100px;
  4. background: transparent;
  5. border-radius: 50%;
  6. border: 2px dashed #000;
  7. -webkit-animation-name: Rotate;
  8. -webkit-animation-duration: 2s;
  9. -webkit-animation-iteration-count: infinite;
  10. -webkit-animation-timing-function: linear;
  11. -moz-animation-name: Rotate;
  12. -moz-animation-duration: 2s;
  13. -moz-animation-iteration-count: infinite;
  14. -moz-animation-timing-function: linear;
  15. -ms-animation-name: Rotate;
  16. -ms-animation-duration: 2s;
  17. -ms-animation-iteration-count: infinite;
  18. -ms-animation-timing-function: linear;
  19. }
  20. .play {
  21. padding: 20px 30px;
  22. font-size: 56px;
  23. }
  24.  
  25. @-webkit-keyframes Rotate
  26. {
  27. from{-webkit-transform:rotate(0deg);}
  28. to{-webkit-transform:rotate(360deg);}
  29. }
  30. @-moz-keyframes Rotate
  31. {
  32. from{-moz-transform:rotate(0deg);}
  33. to{-moz-transform:rotate(360deg);}
  34. }
  35. @-ms-keyframes Rotate
  36. {
  37. from{-ms-transform:rotate(0deg);}
  38. to{-ms-transform:rotate(360deg);}
  39. }

HTML:

  1. <div class="circle">
  2. <div class="play"><i class="fa fa-play"></i></div>
  3. </div>

这个代码我哪里错了?

DEMO JSFIDDEL

解决方法

旋转父级也会旋转子项,所以最好像这里一样单独设置边框样式
  1. .circle {
  2. width: 100px;
  3. height: 100px;
  4. position: relative;
  5. }
  6. .circle .border {
  7. /* content: ''; */
  8. position: absolute;
  9. top: 0;
  10. bottom: 0;
  11. left: 0;
  12. right: 0;
  13. background: transparent;
  14. border-radius: 50%;
  15. border: 2px dashed #000;
  16. -webkit-animation-name: Rotate;
  17. -webkit-animation-duration: 2s;
  18. -webkit-animation-iteration-count: infinite;
  19. -webkit-animation-timing-function: linear;
  20. -moz-animation-name: Rotate;
  21. -moz-animation-duration: 2s;
  22. -moz-animation-iteration-count: infinite;
  23. -moz-animation-timing-function: linear;
  24. -ms-animation-name: Rotate;
  25. -ms-animation-duration: 2s;
  26. -ms-animation-iteration-count: infinite;
  27. -ms-animation-timing-function: linear;
  28. }
  29. .play {
  30. padding: 20px 30px;
  31. font-size: 56px;
  32. }
  33. .stop {
  34. font-size: 12px;
  35. padding: 30px;
  36. text-align: center;
  37. }
  38. @-webkit-keyframes Rotate {
  39. from {
  40. -webkit-transform: rotate(0deg);
  41. }
  42. to {
  43. -webkit-transform: rotate(360deg);
  44. }
  45. }
  46. @-moz-keyframes Rotate {
  47. from {
  48. -moz-transform: rotate(0deg);
  49. }
  50. to {
  51. -moz-transform: rotate(360deg);
  52. }
  53. }
  54. @-ms-keyframes Rotate {
  55. from {
  56. -ms-transform: rotate(0deg);
  57. }
  58. to {
  59. -ms-transform: rotate(360deg);
  60. }
  61. }
  1. <div class="circle">
  2. <div class="border"></div>
  3. <div class="play"><i class="fa fa-play"></i>
  4. </div>
  5. </div>
  6.  
  7. <p>
  8. PS: The icon loading is a bit slow. Wait until it shows up.
  9. </p>
  10.  
  11. <div class="circle">
  12. <div class="border"></div>
  13. <div class="stop">Stop me please</div>
  14. </div>

猜你在找的HTML相关文章