起因
最近听到要开学的消息,就会想到考试,提到考试自然就会想到受本次疫情影响的高考考生。最后琢磨着做一个高考倒计时网页。为了时间长一点,我特地把日期调为了2021年的高考(别问我,我也不知道我是怎么想的)。然后呢。。。我并不会html/css(因为学业繁忙),于是就跟着B站制作新年倒计时网页的视频抄了抄代码,勉强搞出来了。
代码
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Countdown to NCEE</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<h2><span>Countdown to NCEE</span> 2021</h2>
<div class="countdown">
<div id="day">NA</div>
<div id="hour">NA</div>
<div id="minute">NA</div>
<div id="second">NA</div>
</div>
</div>
<script type="text/javascript">
var countDate = new Date('June 7, 2021 00:00:00').getTime();
function nceetime(){
var now = new Date().getTime();
gap = countDate - now;
var second = 1000;
var minute = second * 60;
var hour = minute * 60;
var day = hour * 24;
var d = Math.floor(gap / (day));
var h = Math.floor(gap % (day) / (hour));
var m = Math.floor(gap % (hour) / (minute));
var s = Math.floor(gap % (minute) / second);
document.getElementById('day').innerText = d;
document.getElementById('hour').innerText = h;
document.getElementById('minute').innerText = m;
document.getElementById('second').innerText = s;
}
setInterval(function(){
nceetime();
},1000)
</script>
</body>
</html>
CSS代码
@import url("https://fonts.googleapis.com/css?family=Poppins:100,200,300,400,500,600,700,800,900");
*
{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
body
{
background: #000 url(bg.jpg);
background-attachment: fixed;
background-blend-mode: hard-light;
}
.container{
position: absolute;
top: 80px;
left: 100px;
right: 100px;
bottom: 80px;
background: url(bg.jpg);
background-attachment: fixed;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
box-shadow: 0 50px 50px rgba(0,0,0,0.5),
0 0 0 100px rgba(0,0,0,.1);
}
.container h2 {
text-align: center;
font-size: 10em;
line-height: 0.7em;
color: #333;
margin-top: -80px;
}
.container h2 span{
display: block;
font-weight: 300;
letter-spacing: 6px;
font-size: 0.2em;
}
.countdown{
display: flex;
margin-top: 50px;
}
.countdown div{
position: relative;
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
background: #333;
color: #fff;
margin: 0 15px;
font-size: 3em;
font-weight: 500;
}
.countdown div:before{
content: '';
position: absolute;
bottom: -30px;
left: 0;
width: 100%;
height: 35px;
background: #ff0;
color: #333;
font-size: 0.35em;
line-height: 35px;
font-weight: 300;
}
.container #day:before{
content: 'Days';
}
.container #hour:before{
content: 'Hours';
}
.container #minute:before{
content: 'Minutes';
}
.container #second:before{
content: 'Seconds';
}