练习1_时钟.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. *{
  9. margin: 0;
  10. padding: 0;
  11. }
  12. li{
  13. list-style: none;
  14. }
  15. .box{
  16. width: 404px;
  17. height: 404px;
  18. border: 2px dashed black;
  19. position: fixed;
  20. top: 50%;
  21. left: 50%;
  22. transform: translate(-50%,-50%);
  23. }
  24. .clock{
  25. width: 400px;
  26. height: 400px;
  27. border: 2px solid black;
  28. border-radius: 50%;
  29. position: relative;
  30. }
  31. .clock li{
  32. width: 2px;
  33. height: 6px;
  34. background-color: black;
  35. position: absolute;
  36. top: 0;
  37. left: 50%;
  38. /* transform: translateX(-50%); */
  39. margin-left: -1px;
  40. transform-origin: center 200px;
  41. }
  42. /* .clock li:nth-child(1){
  43. transform: rotate(6deg) translateX(-50%);
  44. }
  45. .clock li:nth-child(2){
  46. transform: rotate(12deg) translateX(-50%);;
  47. } */
  48. .clock li:nth-child(5n+1){
  49. height: 12px;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div class="box">
  55. <div class="clock">
  56. <ul>
  57. <!-- <li></li>
  58. <li></li>
  59. <li></li> -->
  60. </ul>
  61. </div>
  62. </div>
  63. <script>
  64. var oUl = document.getElementsByTagName("ul")[0];
  65. var str = ""
  66. for(var i=0;i<60;i++){
  67. str += "<li style='transform: rotate("+(i*6)+"deg);'></li>"
  68. }
  69. oUl.innerHTML = str;
  70. </script>
  71. </body>
  72. </html>