Show different CSS styles to the site in a time period

Source: Internet
Author: User
The above two sites is based on the time to automatically adjust the site style, in fact, the time to automatically adjust the site style is not a new thing, remember a long time ago have seen similar articles or methods, but did not pay special attention.
Okay, here's how they're implemented, and there are two ways to do it online.
1) using the service-side code
ASP version:
<link rel= "stylesheet" type= "Text/css"
<%
If hour (now) <12 then
Response.Write "Morning.css"
ElseIf Hour (now) <17 then
Response.Write "Day.css"
Else
Response.Write "Night.css"
End If
%>
"/>

PHP Version:
<link rel= "stylesheet" type= "Text/css"
<?php
$hour = Date ("H");
if ($hour < 12)
Echo ' Morning.css ';
else if ($hour < 17)
Echo ' Day.css ';
Else
Echo ' Night.css ';
?>
"/>

2 using JavaScript code
<script type= "Text/javascript" >
<!--
function Getcss () {
Datetoday = new Date ();
Timenow=datetoday.gettime ();
Datetoday.settime (TimeNow);
Thehour = Datetoday.gethours ();
if (thehour<12)
display = "Morning.css";
else if (thehour<17)
display = "Day.css";
Else
display = "Night.css";
(... Want to add more can be ... )

var css = ' < ';
css+= ' link rel= ' stylesheet ' href= ' +display+ ' \/';
css+= ' > ';
document.write (CSS);
}
-->
</script>
Given that the client may not support or disallow JavaScript, you need to set a default CSS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.