Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add task solution #3936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,49 @@
/>
</head>
<body>
<h1>Calendar</h1>
<div class="calendar calendar--start-day-sun calendar--month-length-31">
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
* {
box-sizing: border-box;
}

body {
flex-direction: column;
display: flex;
justify-content: center; /* Вирівнює по горизонталі */
align-items: center; /* Вирівнює по вертикалі */
height: 100vh;
margin: 0;
}

@import 'main';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @import rule is used to include the main SCSS file. Make sure that the main.scss file exists in the same directory or provide the correct path. Note that @import is deprecated in favor of @use and @forward in newer versions of Sass, which offer better modularity and avoid potential conflicts.

62 changes: 62 additions & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
$day-size: 100px;
$border-color: #000;
$default-bg-color: #eee;
$hover-bg-color: #ffbfcb;
$font-size: 30px;
$font-family: Arial, sans-serif;
$columns: 7;
$padding: 10px;
$animation-duration: 0.5s;

.calendar {
display: flex;
flex-wrap: wrap;
gap: 1px;
width: calc(#{$columns} * (#{$day-size} + 1px) - 1px);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation for the calendar width uses a combination of variables and arithmetic operations. Ensure that the calculation accounts for all necessary spacing and border widths to avoid layout issues.

margin: 0 auto;
align-items: center;
counter-reset: day 0;

&__day {
width: $day-size;
height: $day-size;
background-color: $default-bg-color;
border: 1px solid $border-color;
display: flex;
align-items: center;
justify-content: center;
font-family: $font-family;
font-size: $font-size;
position: relative;
cursor: pointer;
transition:
transform $animation-duration,
background-color $animation-duration;
counter-increment: day;

&::before {
content: counter(day);
}

&:hover {
background-color: $hover-bg-color;
transform: translateY(-20px);
}
}

// Позиціюємо перший день у залежності від того, з якого дня починається місяць
@each $day, $index in (mon: 0, tue: 1, wed: 2, thu: 3, fri: 4, sat: 5, sun: 6)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @each loop is used to dynamically create classes for different starting days of the week. Ensure that these classes are correctly applied in the HTML to achieve the desired layout.

{
&--start-day-#{$day} .calendar__day:nth-child(1) {
/* Перший день має "заповнити" необхідне місце за допомогою flex-basis */
margin-left: calc(#{$index} * (#{$day-size} + 1px));
}
}

// Приховуємо додаткові дні для місяців з меншою кількістю днів
@for $i from 28 through 31 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @for loop is used to hide extra days for months with fewer days. Ensure that the logic correctly matches the number of days in each month and that the classes are applied appropriately in the HTML.

&--month-length-#{$i} .calendar__day:nth-child(n + #{$i + 1}) {
display: none;
}
}
}
Loading