Minimalist Calendar - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Minimalist Calendar</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"> <style> body { font-family: 'Arial', sans-serif; background: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .calendar { background: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); overflow: hidden; width: 300px; } .calendar-header { background: #007bff; color: white; text-align: center; padding: 10px; font-size: 18px; } .calendar-header h2 { margin: 0; font-size: 1.5em; } .calendar-header select { background: #007bff; border: none; color: white; font-size: 1em; margin: 0 5px; padding: 5px; } .calendar-header button { background: none; border: none; color: white; cursor: pointer; font-size: 1.2em; } .calendar-header button:focus { outline: none; } .calendar-body { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; padding: 10px; } .calendar-day { width: 30px; height: 30px; display: flex; justify-content: center; align-items: center; border-radius: 50%; cursor: pointer; transition: background 0.3s, transform 0.3s; } .calendar-day:hover { background: #007bff; color: white; transform: scale(1.1); } .calendar-day.active { background: #0056b3; color: white; } .calendar-day span { font-size: 0.9em; } .calendar-footer { text-align: center; padding: 10px; font-size: 14px; } .calendar-footer button { background: #007bff; border: none; color: white; cursor: pointer; font-size: 1em; padding: 5px 15px; border-radius: 5px; transition: background 0.3s; } .calendar-footer button:hover { background: #0056b3; } </style> </head> <body> <div class="calendar"> <div class="calendar-header"> <button type="button" id="prevMonth" title="Previous"><i class="fas fa-chevron-left"></i></button> <select id="monthSelect" title="Month"></select> <select id="yearSelect" title="Year"></select> <button type="button" id="nextMonth" title="Next"><i class="fas fa-chevron-right"></i></button> </div> <div class="calendar-body" id="calendarBody"></div> <div class="calendar-footer"> <button type="button" id="todayBtn">Today</button> </div> </div> <script> const calendarBody = document.getElementById('calendarBody'); const monthSelect = document.getElementById('monthSelect'); const yearSelect = document.getElementById('yearSelect'); const prevMonth = document.getElementById('prevMonth'); const nextMonth = document.getElementById('nextMonth'); const todayBtn = document.getElementById('todayBtn'); let currentDate = new Date(); const months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; function populateMonthSelect() { months.forEach((month, index) => { const option = document.createElement('option'); option.value = index; option.textContent = month; monthSelect.appendChild(option); }); } function populateYearSelect() { const currentYear = new Date().getFullYear(); for (let i = currentYear - 50; i <= currentYear + 50; i++) { const option = document.createElement('option'); option.value = i; option.textContent = i; yearSelect.appendChild(option); } } function renderCalendar(date) { const year = date.getFullYear(); const month = date.getMonth(); const firstDayOfMonth = new Date(year, month, 1).getDay(); const lastDateOfMonth = new Date(year, month + 1, 0).getDate(); const lastDayOfLastMonth = new Date(year, month, 0).getDate(); monthSelect.value = month; yearSelect.value = year; calendarBody.innerHTML = ''; for (let i = firstDayOfMonth; i > 0; i--) { calendarBody.innerHTML += `<div class="calendar-day inactive">${lastDayOfLastMonth - i + 1}</div>`; } for (let i = 1; i <= lastDateOfMonth; i++) { calendarBody.innerHTML += `<div class="calendar-day ${i === date.getDate() ? 'active' : ''}"><span>${i}</span></div>`; } const totalDays = firstDayOfMonth + lastDateOfMonth; const nextDays = 7 - (totalDays % 7); for (let i = 1; i <= nextDays; i++) { calendarBody.innerHTML += `<div class="calendar-day inactive">${i}</div>`; } } prevMonth.addEventListener('click', () => { currentDate.setMonth(currentDate.getMonth() - 1); renderCalendar(currentDate); }); nextMonth.addEventListener('click', () => { currentDate.setMonth(currentDate.getMonth() + 1); renderCalendar(currentDate); }); monthSelect.addEventListener('change', (e) => { currentDate.setMonth(e.target.value); renderCalendar(currentDate); }); yearSelect.addEventListener('change', (e) => { currentDate.setFullYear(e.target.value); renderCalendar(currentDate); }); todayBtn.addEventListener('click', () => { currentDate = new Date(); renderCalendar(currentDate); }); populateMonthSelect(); populateYearSelect(); renderCalendar(currentDate); </script> </body> </html>