使用CSS3实现的player播放按钮

时间:2023-03-09 19:21:04
使用CSS3实现的player播放按钮

完成的效果如下

使用CSS3实现的player播放按钮

查看效果并下载

Step 1:先了解border的原理:

使用CSS3实现的player播放按钮

Step 2:HTML代码结构

  1. <section class="playContainer">
  2. <li class="playBtn">
  3. <a href="#" title="start">Start</a>
  4. </li>
  5. <li class="pauseBtn">
  6. <a href="#" title="pause">Pause</a>
  7. </li>
  8. <li class="stopBtn">
  9. <a href="#" title="stop">Stop</a>
  10. </li>
  11. <li class="forwardBtn playBtn">
  12. <a href="#" title="forward">Forward</a>
  13. <a href="#" title="forward">Forward</a>
  14. </li>
  15. <li class="rewindBtn">
  16. <a href="#" title="rewind">Rewind</a>
  17. <a href="#" title="rewind">Rewind</a>
  18. </li>
  19. <li class="ejectBtn">
  20. <a href="#" class="arrow">Eject</a>
  21. <a href="#" class="dash">Eject</a>
  22. </li>
  23. </section>

Step 3:画背景圆,position:relative

  1. .playContainer li { position: relative; float: left; border: 25px solid #404040; color: #404040; height: 0; width:0; -webkit-border-radius: 100%; -moz-border-radius: 100%; -o-border-radius: 100%; border-radius: 100%; margin: 0 20px; }

使用CSS3实现的player播放按钮

Step 4:画stop按钮,要让按钮居中。

按钮相对外层圆圈绝对定位,从圆圈的中心开始,所以要调整top和left值

stop按钮边长14px,相对原点需要向上、向左移动7个像素,居中。

使用CSS3实现的player播放按钮

全部的CSS如下:

  1. .playContainer { position: relative; float: left; background: rgba(0, 0, 0, 0.8); padding: 20px; }
  2. .playContainer li { position: relative; float: left; border: 25px solid #404040; color: #404040; height: 0; width:0; -webkit-border-radius: 100%; -moz-border-radius: 100%; -o-border-radius: 100%; border-radius: 100%; margin: 0 20px; }
  3. .playContainer a { border-style: solid; text-indent: -9999px; position: absolute; top: -8px; left: -3px;  }
  4. .playBtn a { border-color: transparent transparent transparent #fff; border-width: 8px 0 8px 12px;  width: 0; height: 0; }
  5. .pauseBtn a { border-color: transparent white;  border-width: 0 6px; height: 15px; width: 6px; left: -9px; }
  6. .stopBtn a { border: 7px solid #fff; height: 0; width: 0; left: -7px; top: -7px;}
  7. .forwardBtn a { border-left-width: 8px; left: 1px; }
  8. .forwardBtn a:first-child { margin-left: -7px;  }
  9. .rewindBtn a { border-width: 8px 8px 8px 0; border-color: transparent #fff transparent transparent; width: 0; height: 0; }
  10. .rewindBtn a:first-child { margin-left: -7px; }
  11. .ejectBtn a.arrow { border-width: 0 8px 8px 8px; border-color: transparent transparent #fff transparent; top:-26px; left:-8px; }
  12. ectBtn a.dash { border-width: 0 0 4px; border-color: transparent transparent #fff; height: 0; width:16px; left: -8px; top: 4px; }