Is there a way to show a live date or time of day using only CSS?

My friend claims that he knows how to display a variable, in this case the time of day in H / M / S format, as well as the date, using only CSS. He "forgot" what code is, and thus could not tell me. It seems a little hard to believe that it would be possible; but I'm still curious that this can be done. Any ideas?

+4
source share
2 answers

No, you only use CSS to determine how things look. But you can do it with JS, here is a good list of JS date and time functions:

http://www.quackit.com/javascript/javascript_date_and_time_functions.cfm

and here are some practical examples to get started:

http://www.quackit.com/javascript/tutorial/javascript_date_and_time.cfm (separate the code with <script> tags to make it work)

As an extra note, CSS will be used to make your calendar / watch look beautiful, here is a good example:

http://css-tricks.com/date-display-with-sprites/

+4
source

There may be a way ... but it's technically a hoax.

There are two libraries for CSS: LESS and SASS.

I have not used them much, but they basically allow you to write CSS as an object-oriented approach. As a result, you will be able to use these libraries to get the exact time, but, as I said, you will have to enable these libraries, thus β€œcheating”.

LINKS: LESS: http://lesscss.org/ SASS: http://sass-lang.com/

PS I think LESS is closer to what you would be looking for if you went this way.

+2
source

Source: https://habr.com/ru/post/1398519/


All Articles