Блондинка,
можно так ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Calendar</title>
</head>
<body>
<style>
.day {
border: 1px solid #ccc;
width: 30px;
line-height: 30px;
text-align: center;
margin: 1px;
background-color: #B0C4DE;
}
.month {
display: flex;
flex-wrap:wrap;
width: 238px;
height: 238px;
justify-content: space-around;
margin: 30px auto;
}
.month.vert{
flex-direction: column;
}
.day:nth-child(7n + 6), .day:nth-child(7n + 7){
background-color: #FF85C6;
}
.day:nth-child(-n + 7) {
color: #FFFFFF;
}
</style>
<div class="month"></div>
<script>
var calendar = {
update: function(year, month) {
var stepDay = new Date(year, month, 1);
stepDay.setDate(stepDay.getDate() - ((stepDay.getDay()||7) - 1));
var lastDay = new Date(stepDay);
lastDay.setDate(lastDay.getDate() + 41);
while (stepDay <= lastDay) {
this.days.push(stepDay.getDate());
stepDay.setHours(24);
}
},
render: function() {
var html = '';
for (var i = 0; i < this.days.length; i++) {
html += '<div class="day">' + this.days[i] + '</div>';
}
this.element.innerHTML = html;
},
toggle: function() {
this.element.classList.toggle('vert');
},
};
var today = new Date(),
thisYear = today.getFullYear(),
thisMonth = today.getMonth();
calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
calendar.element = document.querySelector('.month');
calendar.element.addEventListener('click', function() {
calendar.toggle();
});
calendar.update(thisYear, thisMonth);
calendar.render();
</script>
</body>
</html>
|