Блондинка,
Сообщение от рони
|
взять рендер от вариантов с flex или grid.
|
медитируйте, смотрите что добавлено.
<!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,
#month_name {
background-color: hsl(210, 100%, 95%);
color: hsl(210, 100%, 50%);
font: bold 18px serif;
text-align: center;
}
#num_year {
width: 790px;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
padding: 5px;
margin: 0 0 5px 0;
}
#month {
display: inline-block;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
padding: 5px;
width: auto;
}
#month_name {
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
padding: 5px;
margin: 0 0 5px 0;
}
.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_vert {
table-layout: fixed;
width: 100%;
height: 220px;
border: 1px solid hsl(0, 0%, 66%);
border-radius: 4px;
}
.week_day {
width: 20%;
background-color: hsl(210, 100%, 50%);
color: hsl(210, 100%, 95%);
}
.table_month_vert tr:nth-child(n + 6) td.day {
background-color: hsl(340, 100%, 95%);
color: hsl(340, 100%, 50%);
}
.table_month_vert tr:nth-child(1) th {
text-align: center;
}
table.horizontal td {
background-image: -webkit-linear-gradient(top left, #FF0000, #0060BF);
background-image: linear-gradient(to bottom right, #FF0000, #0060BF);
}
</style>
</head>
<body>
<div id="num_year"></div>
<div id="month">
<div id="month_name"></div>
<table class="table_month_vert"></table><br>
<table class="table_month_gor"></table>
</div>
<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(horizontal) {
var html = '';
if (horizontal) {
this.element.classList.add("horizontal");
for (var i = 0, j = 0; i < this.data.length; j = ++i % 7) {
if (j == 0) html += '<tr class="week">';
html += '<td class="day">' + this.data[i] + '</td>';
if (j == 6) html += '</td>';
}
} else {
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];
}
html = html.join('')
}
this.numYear.textContent = this.year;
this.monthName.textContent = this.month;
this.element.innerHTML = html;
},
};
var today = new Date(),
thisYear = today.getFullYear(),
thisMonth = today.getMonth();
calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
calendar.numYear = document.querySelector('#num_year');
calendar.monthName = document.querySelector('#month_name');
calendar.element = document.querySelector('.table_month_vert');
calendar.update(thisYear, thisMonth);
calendar.render(true);
calendar.element = document.querySelector('.table_month_gor');
calendar.render();
</script>
</body>
</html>