Skip to content

Instantly share code, notes, and snippets.

@alireza-saberi
Created March 7, 2017 01:59
Show Gist options
  • Select an option

  • Save alireza-saberi/a4a98534b64bdb2d6e893b2c86184c07 to your computer and use it in GitHub Desktop.

Select an option

Save alireza-saberi/a4a98534b64bdb2d6e893b2c86184c07 to your computer and use it in GitHub Desktop.
This is a simple hack that, we can tell the browser which CSS it should use during the day and which CSS it should use during the night time.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
function setTimedStylesheet(){
var theTime = new Date().getHours();
if ( 8 <= theTime && theTime < 20) {
// day time
document.write("<link rel='stylesheet' href='daytime.css'");
}
else {
// night time
document.write("<link rel='stylesheet' href='timetime.css'");
}
}
setTimedStylesheet();
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment