Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                  <div class="container">
        <h2><span>Hãy Cùng Nhau Đếm Ngược Đến Năm</span> 2021</h2>
    
    <div class="countdown">
        <div id="day"></div>
        <div id="hour"></div>
        <div id="minute"></div>
        <div id="second"></div>
    </div>
</div>
              
            
!

CSS

              
                *{
    margin: 0;
    padding: 0;
    font-family: 'Montserrat', sans-serif;
}

body{
    background: #000 url(https://images.unsplash.com/photo-1588392382834-a891154bca4d?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1589&q=80);
    background-attachment: fixed;
    background-blend-mode: hard-light;
}

.container{
    position: absolute;
    top: 80px;
    left: 100px;
    right: 100px;
    bottom: 80px;
    background: url(https://images.unsplash.com/photo-1588392382834-a891154bca4d?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1589&q=80);
    background-attachment: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    box-shadow: 0 1px 1px rgba(0,0,0,0.12), 
    0 2px 2px rgba(0,0,0,0.12), 
    0 4px 4px rgba(0,0,0,0.12), 
    0 8px 8px rgba(0,0,0,0.12),
    0 16px 16px rgba(0,0,0,0.12);
}


.container h2{
    text-align: center;
    font-size: 10em;
    line-height: 0.7em;
    color: #fff;
    margin-top: -80px;
}
.container h2 span{
    display: block;
    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;
    box-shadow: 0 1px 1px rgba(0,0,0,0.12), 
    0 2px 2px rgba(0,0,0,0.12), 
    0 4px 4px rgba(0,0,0,0.12), 
    0 8px 8px rgba(0,0,0,0.12),
    0 16px 16px rgba(0,0,0,0.12);
}
.countdown div:before{
    content: "";
    position: absolute;
    bottom: -30px;
    left: 0;
    width: 100%;
    height: 50px;
    background: #1E90FF;
    color: #dddddd;
    font-size: 0.35em;
    line-height: 35px;
}

.countdown #day:before{
    content: 'Ngày';
}
.countdown #hour:before{
    content: 'Giờ';
}
.countdown #minute:before{
    content: 'Phút';
}
.countdown #second:before{
    content: 'Giây';
}
              
            
!

JS

              
                /*Lấy thời gian tết âm lịch (mily giây)*/
 var tetAmLich = new Date(2021, 1, 12, 0, 0, 0).getTime();
 
 function newYear() {
     /*Lấy thời gian ngày hiện tại (mily giây) */
     var ngayHienTai = new Date().getTime();

     /*Tính thời gian còn lại (mily giây) */
     thoigianConLai = tetAmLich - ngayHienTai;

    /*Chuyển đơn vị thời gian tương ứng sang mili giây*/
     var giay = 1000;
     var phut = giay * 60;
     var gio = phut * 60;
     var ngay = gio * 24;

    /*Tìm ra thời gian theo ngày, giờ, phút giây còn lại thông qua cách chia lấy dư(%) và làm tròn số(Math.floor) trong Javascript*/
     var d = Math.floor(thoigianConLai / (ngay));
     var h = Math.floor((thoigianConLai % (ngay)) / (gio));
     var m = Math.floor((thoigianConLai % (gio)) / (phut));
     var s = Math.floor((thoigianConLai % (phut)) / (giay));

    /*Hiển thị kết quả ra các thẻ Div với ID tương ứng*/
     document.getElementById("day").innerText = d;
     document.getElementById("hour").innerText = h;
     document.getElementById("minute").innerText = m;
     document.getElementById("second").innerText = s;
 }

/*Thiết Lập hàm sẽ tự động chạy lại sau 1s*/
 setInterval(function () {
     newYear()
 }, 1000)
              
            
!
999px

Console