Hacker News new | past | comments | ask | show | jobs | submit login
Pure Digital CSS, Swiss Made, Clock – No JavaScript, almost no HTML (quaxio.com)
145 points by IceWreck on Dec 31, 2020 | hide | past | favorite | 89 comments



LOL, "This page is best viewed at noon or midnight."


You could just have the server serve up the correct offset when the page is requested. The code delivered to the browser would still be pure CSS.

Of course it might drift over time, but you could also serve up a refresh header to deal with that every hour or so.


Q: Clock always starts at 12:00:00. Is this project a secret tribute to microwaves?

I think it's a generational Easter egg that he went with "microwaves" instead of "VCRs" or even "clock radios."


I think all three of those things came to domestic ubiquity around the same time - late 60s to early 80s.


But microwaves are the only one you'll still find in most homes. I think GP was implying that the author is relatively young.


I think microwaves didn't commonly have a clock in the 60s


They certainly had a timer though.


Mechanical in the earliest units.


Yes, a spring loaded dial that always went back to 0. No clocks.


We had all those things in my house as a kid in the 90s.


Cool project and thanks for explaining it in the FAQ.

The best part about these projects in not seeing the demo but rather learning the clever hacks that make the things tick (no pun).

Reminds me of a video on Vue mastery in which Evan you created a mini vuejs in like 10 mins. Its one thing to use or see something, something totally another to see how it does what it does behind the scenes.


Got a link to that?



This[0] seems to be it but it's behind a paywall. I'd have loved to see it.

[0]: https://www.vuemastery.com/courses/vue3-deep-dive-with-evan-...


The file itself is beautiful and makes me want to put in my pocket and carry around. Hope there's more single beautiful files in the world, reminds me of the single header culture in C where every person can have their own nice little .h file that belongs to themselves.


Put it on a smartwatch and never reload the page!



“i was born in switzerland, therefore this clock is swiss made. QED.”


It can also be viewed by inspecting the page source, which imports this CSS file.


Very cool.

In a similar vein (but much less techinically sophistcated), I recently realized that making "cloze" cards (esp. ones w/ a large number of deletions and/or incremental-reveal cards) in Anki can be made a much less painful process by ditching the native method in favor of an almost entirely CSS implementation (basically, you use Anki's editor to underline the cloze deletions, use a line of JS to add innerText as an attribute to the element, and use CSS to make each answer appear in a little pop-up as you hover over (or touch, if on mobile) a blank. An example: https://streamable.com/xwewa4).


Got a bunch of random markup mixed into the content for me in chromium


Ditto. Here's a Chromium vs Chrome screenshot.

https://imgur.com/a/YShyehD

Note that in chromium there's an implicit style tag that doesn't show up in chrome.

Manually adding

  style {
      display: none;
  }
fixes the issue with no ill effects in Chrome.


Thanks, I’ll fix this. Someone also mentioned the first css rule can cause plugins to get rendered, so worth def worth changing.


I have the same when running Dark Reader, are you using any extensions that modify the css statically ?


I thought it was supposed to look like that (qutebrowser, where it also eatss a ton of memory).


"Even a Broken Clock Is Right Twice a Day"; nice to see folklore not being forgotten even in this digital age ;)


Technically, this clock is either always right (if you load the page at noon/midnight) or always wrong. It's unlikely to get be right twice a day.


Technically, all precise clocks are always wrong ;)


A stopped clock is right twice a day for a duration of 0 seconds. A correct digital clock showing seconds is right 86,400 times a day for a duration of 0 seconds.

So it is 2 x 0 = 0 versus 86,400 x 0 = 0

Looks the same to me!


Except Caesium clocks, which are the definition of time as we measure it.


What impresses me is that this digital clock works just fine in Internet Explorer 11 from 2013, and even works in IE10 from 2012 (doesn’t work in IE9, but, then again, not even text-shadow works in IE9). It doesn’t use any modern CSS, but stuff which has been implemented by browsers since 2012.


You say that as if 2012 is the stone age.

CSS hasn't changed much since its inception in 1996, mostly it's added some selector and layout rules in recent years.


I was a lot more impressed when I thought it was going to show the real time. I wonder if there's a way to accomplish that... Still a neat demo though


One step toward that might be to enable a "fast forward" and "rewind" functionality, as are common on alarm clocks. Then at least you could set it to your current time.


Another thing you could do is server-generate the CSS file, initialized to the current time. But that might be cheating :)


Or you could just offer a panoply of CSS files and allow the user to select the one representing the current time.


Why not just take it a step forward and have the user select the right time once a second?


A history feature would be good, so you can see examples of correct times in the past


Every time I see one of these demos showcasing the constraints they used, it always seems to remind me why nobody does that.

And its not because of the challenge, its because of the result. Which makes me more surprised that other people's activity puts this stuff on my feeds at all.


Kind of cool.. There is something funny happening when using the Dark Reader chrome extension.. imgbox.com/y62Z4gVm Ironically enough, the css goes a bit mad.

I love those css felx's though this is cool


one of the most awesome thing is that I stumbled upon this post at 12:00:xx GMT+7 and didn’t realize that the clock starts on 12:00:00


Very cool but the spacing is off!


> Pure Digital CSS, Swiss Made, Clock. No JavaScript, No HTML

Except for the HTML


Your quote chopped off the asterisk after HTML. See "Unfrequently Asked Questions" for explanation of the asterisk:

view-source:https://www.quaxio.com/pure_css_digital_clock.css


> Your quote chopped off the asterisk after HTML

No, there was (and still is) no asterisk in the title of this post.


Ok, we've put a qualifier in the title above.


Except for the HTML

While technically correct is the best kind of correct, it's worth noting that the entirety of the HTML portion is:

   <link rel="stylesheet" href="pure_css_digital_clock.css">


Firefox doesn't even give me the option to view page source, only selection source. Doing that gives me this:

    <html><head><link rel="stylesheet"
    href="pure_css_digital_clock.css">
    </head><body></body></html>
The inspector works fine, but the inspector also does not present the HTML as it was sent, but rather the DOM that Firefox is rendering.

None of this is important, it's just fun to poke at these CSS demos a little and see how the browser acts.


I can still right click > view page source?


> Firefox doesn't even give me the option to view page source

Looks like they moved it into the Tools -> Web Developers menu. Ctrl+U still works too!


curl is your friend. (Or whatever its Windows equivalent is.)


Powershell added curl(ish) support. I think it’s just aliased to http-transport or something but the basic functions I expect seem to work.


You can also use curl.exe for something more similar to unix-y curl.


Right. For Firefox, I can even remove that line and set the stylesheet using a `Link:` header. Unfortunately, that feature isn't widely adopted by other browsers.


That doesn’t work for this stylesheet because it includes styles for the <link> element.


There’s a way to get other implicit nodes in Firefox...


Well, no, there's a bit more to it than that:

  <html>
   <head>
    <link rel="stylesheet" href="pure_css_digital_clock.css">
   </head>
   <body></body>
  </html>
Indeed the the CSS defines styles for the <body> element. So this whole thing would not be possible there was no HTML (or some structured document representation). See, the part about lack of HTML in the title is completely unnecessary.


This is the implied HTML DOM. The actual HTML file only contains the link element.


And if the client didn't insert the necessary HTML, the thing wouldn't render at all.


That's the HTML that your browser inserts. That HTML isn't present in the data served by the website.


But the CSS rules expect there to be a body element. Regardless of who/what inserted the HTML it's necessary.


It's a cute demo, but it's a timer, not a clock. </pedant>


If you start it at noon, or midnight, it's a clock.


I figured a timer usually counts down and has a start/stop button. A stopwatch counts up, but also has buttons. A clock it is.


How is a "timer" different from a "clock?"


By definition, a timer just counts time (either down or up). So a clock is a kind of timer. But colloquially, a “clock” is a timer that shows the time while a “timer” is one that counts down from a preset amount (for cooking or whatever). Then there’s a “stopwatch” which is a timer that counts up from 0.


> while a “timer” is one that counts down from a preset amount (for cooking or whatever)

I can see this POV, but this isn't really how I've thought of a "timer" myself.

I've always thought a timer was just a thing which kept track of time elapsed (up or down). For example when I'm doing metrics I've always used "timers" to measure how quickly a program runs. I would never call a function which measures how long a process runs a stopwatch function, it would be a timer (or timing) function.

Until I owned an iPhone I've always thought of a stopwatch as the literal physical thing.


By both of your definitions this appears to be a clock. It starts at twelve, not at zero, and it wraps when it gets back to twelve again, making it pretty useless as a measure of elapsed time.

For what it's worth I would define both a timer and a clock as something that ticks(/updates) at a fixed regular interval.


A clock tells me the time of day.

A page which says 12:00:00 every time I go there isn't a clock in my book.


I get what you're saying, but have you never experienced a clock set to the wrong time? Is such a thing really no longer deserving of the title? What about clocks in different locales, are they not clocks for you but clocks for others? Is this demo a clock twice a day? You're the one claiming to be a pedant here.


I think you are taking my top post entirely too seriously.


In the old days you had to wind it and to set it. This one you don’t have to wind, only to set. That’s pretty good in my book!


You can't set it. You can only start it at one of 2 correct start times. If you could set it, then at least it would have parity with VCR clocks.


[flagged]


Not really, it's just a bunch of boxes with borders, and each box has an animation saying when each border is white or black.

The only notable technological "gimmick" is that it doesn't use any more HTML elements than the ones the browser generates automatically from the "severely malformed" HTML it is given.

(Not to devalue the creativity of the demo, though!)

A possibly more elegant way to do this would be by using clip-path and CSS variables to render the digits, this would only require 1 element per digit and would make for more readable animations too.


What's Swiss about this? The programmer is from Switzerland?


Q: Swiss made, how so? A: I was born in Switzerland. By induction, this clock is Swiss made. QED.


From the FAQ:

Q: Swiss made, how so? A: I was born in Switzerland. By induction, this clock is Swiss made. QED.


It’s just for fun, dude. Besides, Switzerland is known for their clock-making.


I didn't see the FAQ. OK. I guess. Still kind of weird. I've never seen software marketed with where it was programmed.

I know this is a tongue in cheek thing, but I find it pretty repulsive to mark a piece of software "Made in X" when it is clearly an international cooperation - CSS, Browsers, TCP protocol, etc is many countries getting together and building stuff. Let's keep nationalism out of software yall.


It's quite a stretch to say that a CSS demo referencing Swiss watches is an example of nationalism


As I said, I acknowledge the tongue-in-cheek aspect. My point about keeping nationalism out of software was more general.


Just to explain the downvotes a bit, in case you're unaware, it's kind of a social faux-pas to say "I acknowledge that this is a joke" and then poison the mood with a semi-related tangent rant about something you find annoying or bad or repulsive.


I don't mind downvotes, we're all adults here and I hope people are downvoting without ulterior motives. Clearly people disagree with what I am saying.

Something that I find repulsive is sort of related (usually Swissmade or Xmade is taking pride in their nationality, aka nationalism), it is not completely tangent. Obviously, there was a reaction in my brains when I saw "Swiss made" that made me comment here and express.


"Made in X" has nothing to do with "nationalism". Also: "Made in US" labels are incredibly useful, with regards to data privacy.


You could get it to synchronise the time with just a teeny bit of JavaScript. Add this CSS:

  *, ::before, ::after {
    animation-delay: var(--delay);
  }
… and this JS:

  var d = new Date();
  document.documentElement.style.setProperty("--delay",
    -(d.getHours() * 3600 +
      d.getMinutes() * 60 +
      d.getSeconds() +
      d.getMilliseconds() / 1000
     ) + "s");
I think this would do it. It roughly matches what I did a few years back for an analogue CSS-only (except for this) clock.

However, this does still have a weakness: if the browser is suspended (e.g. machine in standby) it gets out of sync. It doesn’t care about leap seconds, either. You could fix these things by triggering this position update every so often, but that would be missing the point of it.


Yes, most people reading this thread know that it’s possible with JS, but then it would use javascript which I assume was not the point of the experiment. Trying to suggest javascript is missing the point.


I think there’s a key difference between what I suggest here and doing the entire thing in JavaScript: this is purely using JavaScript to set the initial time; the actual time keeping is done by the browser with a CSS animation, and thus it’s still a clock if JavaScript is unavailable or disabled, just one that starts at 12 o’clock instead of the correct time.


If you just want to set the initial time, you could do it server-side and not break the spirit of it.


You can’t do it server-side because you don’t know the client-side time. The closest you could do would be to choose Swiss time for the sake of it (or UTC if you prefer).

Remember also that the clock will be out of sync if you set it server-side, because of latency between the server and client. This inaccuracy would doubtless besmirch the name of Swiss timepieces. Could be fun hooking into TCP and TLS negotiation to estimate latency in order to compensate in the animation-delay and make it probabilistically more accurate. Now that would be a fun article to read. I’m almost tempted to devise a way to do this myself. I suspect I couldn’t get the necessary information through my standard nginx reverse proxying arrangement and would need to serve the CSS from a different port so that I could handle the negotiation in a process of my own and observe the timings.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: