A website can switch different CSS styles you should all understand, like the well-known Tencent in this year's revision also increased the function of switching skin. According to the time to automatically adjust the site style is a good idea, the time to automatically adjust the site style is not new, remember a long time ago have seen similar articles or methods, but did not pay special attention. Here are a few ways to implement them, and there are two ways to implement them online:
First, the use of 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 ';
?>
"/>
Second, the use of 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