GithubHelp home page GithubHelp logo

digitalclockcss's Introduction

  1. Overview

Pure Digital CSS clock. No JavaScript, no HTML(*). Not even for the text.

Looks something like this, but something happens every second!

|  --\    /-\  /-\    /-\  /-\
|    |    | |  | |    | |  | |
|  /-/    | |  | |    | |  | |
|  |      | |  | |    | |  | |
|  \--    \-/  \-/    \-/  \-/

Q: Why build a digital clock? A: An analog pure css clock is banal at best.

Q: Why the asterisk after HTML. A: (*) Browser's implicit HTML elements are used. I also have to explicitly set the tag because most browsers don't support Link headers and stylesheets. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link https://bugs.chromium.org/p/chromium/issues/detail?id=692359

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

Q: Ok, how does this work? A: This kind of LCD display is called a 7-segment display. Each digit is split in seven segments. Depending on which segments are dark or light, the result looks like a digit between 0 and 9.

In this hack, I used CSS animations to animate borders in a very specific way, resulting in the appearance of a digital clock. I need two HTML elements per digit.

Q: How do you avoid using any HTML? A: Browsers automatically create implicit HTML nodes when a document is bare. In my case, I set the tag and get implicit , , and tags. This might not seem enough but I can use ::before and ::after selectors, resulting in exactly the 12 nodes I need.

Q: Why do you set content: ""? A: Without setting content, ::before and ::after nodes are invisible.

Q: Why do you set display: block? A: Without setting the display attribute, html, head, and link are invisible.

Q: Why do you set border: 1px solid #fff? A: Safari doesn't animate attributes which haven't previously been set.

Q: What's the clip-path? A: CSS borders provide a natural bevel which lines up with how 7-segment displays are supposed to look. I used the clip-path to get a similar bevel effect on the outer corners.

Q: Why do you set box-sizing: border-box? A: It solves a pixel rounding issue with Safari. I use vw, vh, and vmin to make the clock look good and centered irrespective of the screen size. This can cause rounding issues since a box might land on the boundary of two pixels. CSS doesn't offer a ton of control when it comes to pixel rounding, but box-sizing seems to work ¯_(ツ)_/¯.

digitalclockcss's People

Contributors

kpac567 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.