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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
49 changes: 48 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,53 @@
<link rel="stylesheet" href="./style.css">
</head>
<body>
<h1>Stars</h1>
<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>

<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>
</div>
</body>
</html>
47 changes: 47 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
body {
margin: 0;
}

.stars {
display: flex;
width: 96px;

Choose a reason for hiding this comment

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

3'rd point in checklist

Choose a reason for hiding this comment

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

isn't fixed. No needs to hardcode width

}

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

Choose a reason for hiding this comment

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

apply background shorthand

color: #e5e5e5;

Choose a reason for hiding this comment

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

redundant

Suggested change
color: #e5e5e5;

}

.stars__star:not(:last-child) {
margin-right: 4px;
}

.stars--5 .stars__star {
background-image: url("./images/star-active.svg");
}
Copy link

Choose a reason for hiding this comment

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

Move it down as other selectors for modifiers


.stars--1 .stars__star:nth-child(1) {
background-image: url("./images/star-active.svg");
}

.stars--2 .stars__star:nth-child(1),
.stars--2 .stars__star:nth-child(2) {
background-image: url("./images/star-active.svg");
}

.stars--3 .stars__star:nth-child(1),
.stars--3 .stars__star:nth-child(2),
.stars--3 .stars__star:nth-child(3) {
background-image: url("./images/star-active.svg");
}

.stars--4 .stars__star:nth-child(1),
.stars--4 .stars__star:nth-child(2),
.stars--4 .stars__star:nth-child(3),
.stars--4 .stars__star:nth-child(4) {
background-image: url("./images/star-active.svg");
}

Choose a reason for hiding this comment

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

this type of adding styles isn't flexible. Imagine if you have a case with 10 stars or even more?

  1. use :nth-child(-n + {{here_will_be_a_number_from_1_to_5}})
    Example:
    .my__star:nth-child(-n + 4)
  2. if your selectors have the same style use them as a group
    Example:
.my__selector1, 
.my__selector2 {
  color: #ff0000;
}

Loading