S O S
как выделить цветом в календарь сегодн число, сегодн день недели, текущий месяц, дни недели других месяцев, и сделать навигацию по годам?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#table_year {
table-layout: fixed;
width: 100%;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
}
.td_month {
width: 260px;
height: 270px;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
}
#num_year,
#January,
#February,
#March,
#April,
#May,
#June,
#July,
#August,
#September,
#October,
#November,
#December {
background-color: hsl(210, 100%, 95%);
color: hsl(210, 100%, 50%);
font: bold 18px serif;
text-align: center;
border: 1px solid hsl(0,0%,66%);
border-radius: 4px;
padding: 5px;
margin: 0 0 5px 0;
}
#num_year {
font: bold 24px serif;
width: 780px;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
padding: 5px;
margin: 0 0 5px 0;
}
#month1,
#month2,
#month3,
#month4,
#month5,
#month6,
#month7,
#month8,
#month9,
#month10,
#month11,
#month12 {
display: inline-block;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
padding: 5px;
width: auto;
}
.day {
border: 1px solid hsl(0, 0%, 66%);
width: auto;
line-height: 30px;
text-align: center;
margin: 1px;
background-color: hsl(210, 100%, 95%);
color: hsl(210, 100%, 50%);
}
.table_month {
table-layout: fixed;
width: 100%;
height: 220px;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
}
.table_month tr td:nth-child(1) {
width: 20%;
font-weight: bold;
}
.table_month tr td.day:nth-child(1) {
background-color: hsl(210, 100%, 88%);
color: hsl(210, 100%, 60%);
}
.table_month tr:nth-child(n + 6) td.day:nth-child(1) {
background-color: hsl(348, 100%, 88%);
color: hsl(348, 100%, 60%);
}
.table_month tr:nth-child(n + 6) td.day {
background-color: hsl(348, 100%, 95%);
color: hsl(348, 100%, 50%);
}
#year_input {
border: 1px solid hsl(0,0%,66%);
display: inline-block;
text-align: center;
font: bold 24px serif;
color: hsl(210,100%,50%);
width: 100px;
}
</style>
</head>
<body>
<div id="num_year">
Календарь на
<button class="year_minus">◀</button>
<input id="year_input" type="number" size="4" value="2021"/>
<button class="year_plus">▶</button>
год.</button><br/>
<button id="presently">сегодня</button>
</div>
<table id="table_year">
<tr>
<td class="td_month">
<div id="month1">
<div id="January"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month2">
<div id="February"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month3">
<div id="March"></div>
<table class="table_month"></table>
</div>
</td>
</tr>
<tr>
<td class="td_month">
<div id="month4">
<div id="April"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month5">
<div id="May"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month6">
<div id="June"></div>
<table class="table_month"></table>
</div>
</td>
</tr>
<tr>
<td class="td_month">
<div id="month7">
<div id="July"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month8">
<div id="August"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month9">
<div id="September"></div>
<table class="table_month"></table>
</div>
</td>
</tr>
<tr>
<td class="td_month">
<div id="month10">
<div id="October"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month11">
<div id="November"></div>
<table class="table_month"></table>
</div>
</td>
<td class="td_month">
<div id="month12">
<div id="December"></div>
<table class="table_month"></table>
</div>
</td>
</tr>
</table>
<script>
var calendar = {
update: function(year, month) {
this.year = year;
this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
var startDay = new Date(year, month, 1);
var offsetDay = (startDay.getDay() || 7) - 1;
startDay.setDate(startDay.getDate() - offsetDay);
var lastDay = new Date(startDay);
var days = new Date(year, month + 1, 0).getDate();
days = Math.ceil((days + offsetDay) / 7) * 7;
lastDay.setDate(lastDay.getDate() + days);
this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
while (startDay < lastDay) {
this.data.push(startDay.getDate());
startDay.setHours(24);
}
},
render: function() {
var html = ['<tr class="week_day">', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
for (var i = 0; i < this.data.length; i++) {
html[i % 7] += '<td class="day">' + this.data[i];
}
this.monthName.textContent = this.month;
this.element.innerHTML = html.join('');
},
};
var today = new Date(),
thisYear = today.getFullYear(),
thisMonth = today.getMonth(),
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
calendar.numYear = document.querySelector('#num_year');
months.forEach((v,i) => {
calendar.monthName = document.querySelector(`#${v}`);
calendar.element = document.querySelectorAll('.table_month')[i];
calendar.update(thisYear, i);
calendar.render();
});
</script>
</body>
</html>