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 #4942

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Implement the [Stars Block](https://www.figma.com/file/ojkArVazq7vsX0nbpn9CxZ/Moyo-%2F-Catalog-(ENG)?node-id=11325%3A2960) used in a card and catalog.

Hold `Alt` key (`Option` on MacOS) to measure distances in Figma.
Hold `Alt` key (`Option` on MacOS) to measure distances in Figma.

> Here are the [Layout Tasks Instructions](https://mate-academy.github.io/layout_task-guideline)

Expand All @@ -22,8 +22,8 @@ Hold `Alt` key (`Option` on MacOS) to measure distances in Figma.

❗️ Replace `<your_account>` with your Github username and copy the links to `Pull Request` description:

- [DEMO LINK](https://<your_account>.github.io/layout_stars/)
- [TEST REPORT LINK](https://<your_account>.github.io/layout_stars/report/html_report/)
- [DEMO LINK](https://LiliiaVol.github.io/layout_stars/)
- [TEST REPORT LINK](https://LiliiaVol.github.io/layout_stars/report/html_report/)

❗️ Copy this `Checklist` to the `Pull Request` description after links, and put `- [x]` before each point after you checked it.

Expand Down
50 changes: 49 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,54 @@
/>
</head>
<body>
<h1>Stars</h1>
<div class="container">

Choose a reason for hiding this comment

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

It would be better to use semantic tags where possible. For example, instead of using a div with class container, you could use a section or main tag. This will improve your page SEO and help screen readers. Remember, div does not have any meaning.

<div class="stars stars--0">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
</div>
Comment on lines +17 to +23

Choose a reason for hiding this comment

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

Consider adding some meaningful content inside these div tags. If these are just placeholders for future content, it's ok, but if not, they should contain some content. Empty elements can lead to confusion and may not be accessible.


<div class="stars stars--1">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
</div>

<div class="stars stars--2">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
</div>

<div class="stars stars--3">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
</div>

<div class="stars stars--4">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
</div>

<div class="stars stars--5">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
Comment on lines +17 to +62

Choose a reason for hiding this comment

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

Consider adding some comments or labels to describe what these elements are for. It's not clear what the purpose of these div elements with the class stars and stars__star is.

</div>
</div>
</body>
</html>
143 changes: 143 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,144 @@
/* add styles here */
body {
margin: 0;
padding: 0;
box-sizing: border-box;
}

Choose a reason for hiding this comment

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

Don't use tag names for styling (except html and body). Although this is an exception, it's better to avoid setting global styles such as margin, padding, and box-sizing on the body tag. It's more common to set these on the * selector. But, as per the checklist, using * selector is not recommended due to its impact on performance. So, it's better to set these properties on individual elements as needed.

Choose a reason for hiding this comment

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

You are using the '*' selector here. This can impact performance as this selector applies styles to every single element in the page. It's better to apply styles only to the elements that require them.


.container {
display: flex;
flex-direction: column;
}

.stars {
display: flex;
}

.stars__star {
width: 16px;
height: 16px;
margin-right: 4px;
background-image: url(images/star.svg);
background-repeat: no-repeat;
background-position: center;
}

.stars--1 .stars__star:nth-child(1) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}
Comment on lines +26 to +32

Choose a reason for hiding this comment

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

You are repeating styles for each '.stars--n .stars__star:nth-child(-n + n)' selector. This is not efficient. Try to avoid repeating styles as much as possible. You can create a common class for the active stars and apply the styles to this class instead.


.stars--2 .stars__star:nth-child(1) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--2 .stars__star:nth-child(2) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--3 .stars__star:nth-child(1) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--3 .stars__star:nth-child(2) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--3 .stars__star:nth-child(3) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--4 .stars__star:nth-child(1) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--4 .stars__star:nth-child(2) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--4 .stars__star:nth-child(3) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--4 .stars__star:nth-child(4) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--5 .stars__star:nth-child(1) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--5 .stars__star:nth-child(2) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--5 .stars__star:nth-child(3) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--5 .stars__star:nth-child(4) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

.stars--5 .stars__star:nth-child(5) {
margin-right: 4px;
width: 16px;
height: 16px;
background-image: url(images/star-active.svg);
background-repeat: no-repeat;
}

Choose a reason for hiding this comment

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

The styles for .stars__star are repeated multiple times for different parent classes .stars--1, .stars--2, etc. This repetition can be avoided by using the :nth-child(-n+X) pseudo-class, where X is the number of active stars. For example, .stars--1 .stars__star:nth-child(-n+1) will select the first child of the parent .stars--1, .stars--2 .stars__star:nth-child(-n+2) will select the first two children of the parent .stars--2, and so on. This way, you will avoid repeating the same styles and your CSS will be much cleaner and easier to maintain.

Loading