Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Calander Extended</title>

</head>

<body onload="calander()">
    <div class="cal-body">
        <div class="month">
            <p id="dateDisplay"></p>
            <ul>
                <li class="prev">&#10094;</li>
                <li class="next">&#10095;</li>
                <li class='month-title'>
                    <span style="font-size:18px" class="month-name"></span>
                    <br>
                    <span class='year' style="font-size:15px"></span>
                </li>
            </ul>
        </div>
        <div class="cal-data">
            <ul class="weekdays">
                <li>Mo</li>
                <li>Tu</li>
                <li>We</li>
                <li>Th</li>
                <li>Fr</li>
                <li>Sa</li>
                <li>Su</li>
            </ul>

            <ul class="days">
            </ul>

        </div>
    </div>


    
</body>

</html>
              
            
!

CSS

              
                       html {
            display: flex;
            justify-content: center;
            align-items: center;
            margin: auto;
            height: 100vh;
        }
        
        * {
            box-sizing: border-box;
        }
        
        ul {
            list-style-type: none;
        }
        
        body {
            font-family: Verdana, sans-serif;
        }
        
        .cal-body {
            display: flex;
            flex-direction: row-reverse;
        }
        
        .cal-data {
            width: 70%;
        }
        
        .month {
            padding: 10px 10px;
            width: 40%;
            background: #d75027;
            text-align: center;
        }
        
        .month p {
            font-size: 50px;
            color: white;
            margin: 0;
            padding: 4px;
        }
        
        .month ul {
            margin: 0;
            padding: 0;
        }
        
        .month ul li {
            color: white;
            font-size: 10px;
            text-transform: uppercase;
            letter-spacing: 2px;
            /* font-weight: 900; */
        }
        
        .month .prev {
            float: left;
            padding-top: 10px;
            cursor: pointer;
        }
        
        .month .next {
            float: right;
            padding-top: 10px;
            cursor: pointer;
        }
        
        .weekdays {
            margin: 0;
            padding: 10px 0;
            background-color: #ce7256;
        }
        
        .weekdays li {
            display: inline-block;
            width: 13.6%;
            color: #ffe5e5;
            text-align: center;
        }
        
        .days {
            padding: 10px 0;
            background: #eee;
            margin: 0;
        }
        
        .days li {
            list-style-type: none;
            display: inline-block;
            width: 13.6%;
            text-align: center;
            margin-bottom: 5px;
            font-size: 15px;
            color: #777;
            margin-left: 3px;
        }
        
        .active {
            padding: 5px;
            background: #d75027;
            color: white !important
        }
        /* Add media queries for smaller screens */
        
        @media screen and (max-width:720px) {
            .weekdays li,
            .days li {
                width: 12.1%;
            }
        }
        
        @media screen and (max-width: 420px) {
            .weekdays li,
            .days li {
                width: 12.5%;
            }
            .days li .active {
                padding: 2px;
            }
        }
        
        @media screen and (max-width: 290px) {
            .weekdays li,
            .days li {
                width: 12.2%;
            }
        }
              
            
!

JS

              
                        let daylist = document.querySelector('.days')
        let monthName = document.querySelector('.month-name')
        let yearName = document.querySelector('.year')
        let prev = document.querySelector('.prev')
        let next = document.querySelector('.next')
        let dateDisplay = document.querySelector('#dateDisplay')


        let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'july', 'August', 'September', 'October', 'November', 'December']
        var dt = new Date();
        var month = dt.getMonth() + 1;
        var year = dt.getFullYear();
        var currentDay = dt.getDate();

        prev.addEventListener('click', event => {
            if (month === 1) {
                month = 12;
                year -= 1
            } else {
                month = month - 1;
            }
            calander();
        })
        next.addEventListener('click', event => {
            if (month === 12) {
                month = 1;
                year += 1
            } else {
                month = month + 1;

            }
            calander()
        })

        const calander = () => {
            daylist.innerHTML = ''
            daysInMonth = new Date(year, month, 0).getDate();
            dayNumber = new Date(year, month - 1, 1).getDay();

            console.log(year, month, monthName, dayNumber)

            monthName.innerHTML = monthNames[month - 1]
            yearName.innerHTML = year;
            dateDisplay.textContent = currentDay

            let gaps;
            if (dayNumber === 0) {
                gaps = 6
                console.log(gaps)
            } else {
                gaps = dayNumber - 1
            }

            for (var day = -gaps + 1; day <= daysInMonth; day++) {
                const days = document.createElement('li')

                if (day <= 0) {
                    days.innerHTML = "";
                    daylist.appendChild(days);
                } else if (day === currentDay && month === dt.getMonth() + 1 && year === dt.getFullYear()) {
                    days.setAttribute('class', 'active');
                    days.innerHTML = day;
                    daylist.appendChild(days);
                } else {
                    days.innerHTML = day;
                    daylist.appendChild(days);
                }
            }
        }

              
            
!
999px

Console