• We just launched and are currently in beta. Join us as we build and grow the community.

Simple Analog Clock Using HTML/CSS

m64m65b42b42

Couch Co-Op King
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
130
Likes
36
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Analog Clock Using HTML/CSS

This is a simple analog clock created using HTML and CSS3 only, with no images involved.

As such, you can easily customize the size of the clock and its colors etc. The analog clock works in IE9+ and all versions of other browsers, including on mobile.

Hope this work will help you in your project.
HTML Source Code

  1. <div

    id

    =

    "liveclock"

    class

    =

    "outer_face"

    >
  2. <div

    class

    =

    "marker oneseven"

    ></

    div

    >
  3. <div

    class

    =

    "marker twoeight"

    ></

    div

    >
  4. <div

    class

    =

    "marker fourten"

    ></

    div

    >
  5. <div

    class

    =

    "marker fiveeleven"

    ></

    div

    >

  6. <div

    class

    =

    "inner_face"

    >
  7. <div

    class

    =

    "hand hour"

    ></

    div

    >
  8. <div

    class

    =

    "hand minute"

    ></

    div

    >
  9. <div

    class

    =

    "hand second"

    ></

    div

    >
  10. </

    div

    >
  11. </

    div

    >

CSS Style

  1. .outer_face

    {
  2. position

    :

    relative

    ;
  3. width

    :

    200px

    ;

    /* width of clock */
  4. height

    :

    200px

    ;

    /* height of clock */
  5. border-radius

    :

    200px

    ;

    /* clock round corner radius */
  6. background

    :

    white

    ;
  7. box-shadow

    :

    inset

    0

    0

    10px

    gray

    ;
  8. border

    :

    0

    solid

    gray

    ;

    /* thickness of outer border */
  9. }

  10. .outer_face

    ::

    before

    ,

    .outer_face

    ::

    after

    ,

    .outer_face

    .marker

    {

    /* time markers syle */
  11. content

    :

    ""

    ;
  12. position

    :

    absolute

    ;
  13. width

    :

    8px

    ;

    /* width of 12-6 and 3-9 markers */
  14. height

    :

    100%

    ;
  15. background

    :

    black

    ;
  16. z-index

    :

    0

    ;
  17. left

    :

    50%

    ;
  18. margin-left

    :

    -4px

    ;

    /* set this value of 1/2 marker width */
  19. top

    :

    0
  20. }

  21. .outer_face

    ::

    after

    {
  22. -moz-transform:

    rotate

    (

    90deg

    )

    ;
  23. -ms-transform:

    rotate

    (

    90deg

    )

    ;
  24. -webkit-transform:

    rotate

    (

    90deg

    )

    ;
  25. transform

    :

    rotate

    (

    90deg

    )
  26. }

  27. .outer_face

    .marker

    {
  28. background

    :

    gray

    ;
  29. width

    :

    6px

    ;

    /* width of all other markers */
  30. margin-left

    :

    -3px

    /* set this value of 1/2 marker width */
  31. }

  32. .outer_face

    .marker

    .oneseven

    {
  33. -moz-transform:

    rotate

    (

    30deg

    )

    ;
  34. -ms-transform:

    rotate

    (

    30deg

    )

    ;
  35. -webkit-transform:

    rotate

    (

    30deg

    )

    ;
  36. transform

    :

    rotate

    (

    30deg

    )
  37. }

  38. .outer_face

    .marker

    .twoeight

    {
  39. -moz-transform:

    rotate

    (

    60deg

    )

    ;
  40. -ms-transform:

    rotate

    (

    60deg

    )

    ;
  41. -webkit-transform:

    rotate

    (

    60deg

    )

    ;
  42. transform

    :

    rotate

    (

    60deg

    )
  43. }

  44. .outer_face

    .marker

    .fourten

    {
  45. -moz-transform:

    rotate

    (

    120deg

    )

    ;
  46. -ms-transform:

    rotate

    (

    120deg

    )

    ;
  47. -webkit-transform:

    rotate

    (

    120deg

    )

    ;
  48. transform

    :

    rotate

    (

    120deg

    )
  49. }

  50. .outer_face

    .marker

    .fiveeleven

    {
  51. -moz-transform:

    rotate

    (

    150deg

    )

    ;
  52. -ms-transform:

    rotate

    (

    150deg

    )

    ;
  53. -webkit-transform:

    rotate

    (

    150deg

    )

    ;
  54. transform

    :

    rotate

    (

    150deg

    )
  55. }

  56. .inner_face

    {
  57. position

    :

    relative

    ;
  58. width

    :

    88%

    ;
  59. height

    :

    88%

    ;
  60. background

    :

    white

    ;
  61. -moz-border-radius:

    1000px

    ;
  62. -webkit-border-radius:

    1000px

    ;
  63. border-radius

    :

    1000px

    ;
  64. z-index

    :

    1000

    ;
  65. left

    :

    6%

    ;

    /* set this value of 1/2 width value*/
  66. top

    :

    6%

    /* set this value of 1/2 height value*/
  67. }

  68. .inner_face

    ::

    before

    {
  69. /* clock center circle small */
  70. content

    :

    ""

    ;
  71. width

    :

    18px

    ;

    /* width of inner circle */
  72. height

    :

    18px

    ;

    /* height of inner circle */
  73. border-radius

    :

    18px

    ;
  74. margin-left

    :

    -9px

    ;

    /* set this value of 1/2 width value*/
  75. margin-top

    :

    -9px

    ;

    /* set this value of 1/2 height value*/
  76. background

    :

    black

    ;
  77. position

    :

    absolute

    ;
  78. top

    :

    50%

    ;
  79. left

    :

    50%

    ;
  80. box-shadow

    :

    0

    0

    30px

    blue

    ;
  81. }

  82. .inner_face

    ::

    after

    {
  83. content

    :

    "QUARTZ"

    ;
  84. position

    :

    absolute

    ;
  85. width

    :

    100%

    ;
  86. font

    :

    normal

    0.8em

    Arial;
  87. color

    :

    gray

    ;
  88. text-align

    :

    center

    ;
  89. top

    :

    85%
  90. }

  91. .hand

    ,

    .hand

    .hour

    {
  92. position

    :

    absolute

    ;
  93. width

    :

    4px

    ;

    /* width of hour hand */
  94. height

    :

    30%

    ;

    /* height of hour hand */
  95. top

    :

    20%

    ;

    /* set top to 50% - height */
  96. left

    :

    50%

    ;
  97. margin-left

    :

    -2px

    ;

    /* set this value to 1/2 width */
  98. background

    :

    black

    ;
  99. -moz-transform:

    rotate

    (

    0deg

    )

    ;
  100. -ms-transform:

    rotate

    (

    0deg

    )

    ;
  101. -webkit-transform:

    rotate

    (

    0deg

    )

    ;
  102. transform

    :

    rotate

    (

    0deg

    )

    ;
  103. -moz-transform-origin:

    bottom

    ;
  104. -ms-transform-origin:

    bottom

    ;
  105. -webkit-transform-origin:

    bottom

    ;
  106. transform-origin

    :

    bottom

    ;
  107. z-index

    :

    -1

    ;
  108. -moz-box-shadow:

    0

    0

    3px

    gray

    ;
  109. -webkit-box-shadow:

    0

    0

    3px

    gray

    ;
  110. box-shadow

    :

    0

    0

    3px

    gray
  111. }

  112. .hand

    .minute

    {
  113. height

    :

    45%

    ;

    /* height of min hand */
  114. top

    :

    5%

    ;

    /* set top to 50% - height */
  115. width

    :

    5px

    ;

    /* width of min hand */
  116. margin-left

    :

    -2.5px

    ;

    /* set this value to 1/2 width */
  117. }

  118. .hand

    .second

    {
  119. height

    :

    50%

    ;

    /* height of sec hand */
  120. width

    :

    2px

    ;

    /* width of sec hand */
  121. margin-left

    :

    -1px

    ;

    /* set this value to 1/2 width */
  122. top

    :

    0

    ;
  123. background

    :

    red
  124. }

Result:

result_12.png


And, that's all, you can use this to put in your program.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

440,010

316,559

316,568

Top