mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-19 21:09:51 +08:00
chore(curriculum): update stylized todo list lab (#57549)
This commit is contained in:
parent
f5163eb28a
commit
69d81c9664
@ -17,22 +17,22 @@ Fulfill the user stories below and get all the tests to pass to complete the lab
|
||||
1. You should have an unordered list with the class `todo-list`.
|
||||
2. Inside the unordered list, you should have four list items.
|
||||
3. Inside each list item, there should be:
|
||||
|
||||
|
||||
- An `input` element with the type `checkbox` and `id` set to a unique value.
|
||||
- A `label` element with the `for` attribute set to the corresponding `input` element's `id`.
|
||||
- An unordered list with the class `sub-item`.
|
||||
- A list item with an anchor element in it. The anchor should have the class `sub-item-link`, a valid `href` value, and a `target` value that makes the link open in a new tab.
|
||||
|
||||
|
||||
4. You should remove the default list style from your `.todo-list`.
|
||||
5. Your anchor elements shouldn't have any default text decoration.
|
||||
6. You should set the text color of the links to a color of your choice.
|
||||
7. When your links are visited, the color should change to another color of your choice.
|
||||
8. When your links are hovered over, the color should change to another color of your choice.
|
||||
9. When your links are focused, there should be a colored outline around the link.
|
||||
9. When your links are focused, there should be a colored outline around the link.
|
||||
10. When your links are clicked, the color should change to another color of your choice.
|
||||
|
||||
**Note:** Be sure to link your stylesheet in your HTML and apply your CSS.
|
||||
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have an unordered list with the class `todo-list`.
|
||||
@ -44,30 +44,37 @@ assert.exists(document.querySelector('.todo-list'));
|
||||
You should remove the default list style from your `.todo-list`.
|
||||
|
||||
```js
|
||||
assert(new __helpers.CSSHelp(document).getStyle('.todo-list')?.listStyleType === 'none' || new __helpers.CSSHelp(document).getStyle('.todo-list')?.listStyle === 'none');
|
||||
const isListStyleTypeNone =
|
||||
new __helpers.CSSHelp(document).getStyle('.todo-list')?.listStyleType ===
|
||||
'none';
|
||||
const isListStyleNone =
|
||||
new __helpers.CSSHelp(document).getStyle('.todo-list')?.listStyle === 'none';
|
||||
assert.isTrue(isListStyleTypeNone || isListStyleNone);
|
||||
```
|
||||
|
||||
You should have four list items inside the unordered list.
|
||||
|
||||
```js
|
||||
const li = document.querySelectorAll('.todo-list li');
|
||||
assert.strictEqual(li.length, 8);
|
||||
assert.lengthOf(li, 8);
|
||||
```
|
||||
|
||||
Each list item should contain an `input` element with the type `checkbox`.
|
||||
|
||||
```js
|
||||
const checkboxes = document.querySelectorAll('.todo-list li input[type="checkbox"]');
|
||||
assert.strictEqual(checkboxes.length, 4);
|
||||
const checkboxes = document.querySelectorAll(
|
||||
'.todo-list li input[type="checkbox"]'
|
||||
);
|
||||
assert.lengthOf(checkboxes, 4);
|
||||
```
|
||||
|
||||
All of the `input` elements should have an `id`.
|
||||
|
||||
```js
|
||||
const inputs = document.querySelectorAll('input');
|
||||
assert(!!inputs.length);
|
||||
assert.isAbove(inputs.length, 0);
|
||||
for (let input of inputs) {
|
||||
assert.isAbove(input?.id.length, 0);
|
||||
assert.isAbove(input?.id.length, 0);
|
||||
}
|
||||
```
|
||||
|
||||
@ -75,23 +82,25 @@ After the `label` elements, there should be an unordered list with the class `su
|
||||
|
||||
```js
|
||||
const labelSbItems = document.querySelectorAll('label+ul.sub-item');
|
||||
assert.equal(labelSbItems.length, 4);
|
||||
assert.lengthOf(labelSbItems, 4);
|
||||
```
|
||||
|
||||
The `li` inside the `ul` with the class `sub-item` should have an anchor element with the class `sub-item-link`.
|
||||
|
||||
```js
|
||||
const allItems = document.querySelectorAll('label + ul.sub-item li a.sub-item-link');
|
||||
assert.equal(allItems.length, 4);
|
||||
const allItems = document.querySelectorAll(
|
||||
'label + ul.sub-item li a.sub-item-link'
|
||||
);
|
||||
assert.lengthOf(allItems, 4);
|
||||
```
|
||||
|
||||
All of the anchor elements should have a valid `href`.
|
||||
|
||||
```js
|
||||
const links = document.querySelectorAll('a');
|
||||
assert(!!links.length);
|
||||
assert.isAbove(links.length, 0);
|
||||
for (let link of links) {
|
||||
assert.isAbove(link.href.length, 0);
|
||||
assert.isAbove(link.href.length, 0);
|
||||
}
|
||||
```
|
||||
|
||||
@ -99,9 +108,9 @@ All of the `anchor` elements should have a text.
|
||||
|
||||
```js
|
||||
const links = document.querySelectorAll('a');
|
||||
assert(!!links.length);
|
||||
assert.isAbove(links.length, 0);
|
||||
for (let link of links) {
|
||||
assert.isAbove(link.innerText.length, 0);
|
||||
assert.isAbove(link.innerText.length, 0);
|
||||
}
|
||||
```
|
||||
|
||||
@ -109,9 +118,9 @@ All of the `label` elements should have a `for` attribute.
|
||||
|
||||
```js
|
||||
const labels = document.querySelectorAll('label');
|
||||
assert(!!labels.length);
|
||||
assert.isAbove(labels.length, 0);
|
||||
for (let label of labels) {
|
||||
assert.isAbove(label.htmlFor.length, 0);
|
||||
assert.isAbove(label.htmlFor.length, 0);
|
||||
}
|
||||
```
|
||||
|
||||
@ -119,9 +128,9 @@ All of the `label` elements should have some text.
|
||||
|
||||
```js
|
||||
const labels = document.querySelectorAll('label');
|
||||
assert(!!labels.length);
|
||||
assert.isAbove(labels.length, 0);
|
||||
for (let label of labels) {
|
||||
assert.isAbove(label.innerText.length, 0);
|
||||
assert.isAbove(label.innerText.length, 0);
|
||||
}
|
||||
```
|
||||
|
||||
@ -129,43 +138,62 @@ Each `a` element should have a `target` attribute with the value of `_blank`.
|
||||
|
||||
```js
|
||||
const anchors = document.querySelectorAll('a');
|
||||
assert(!!anchors.length);
|
||||
assert.isAbove(anchors.length, 0);
|
||||
for (let anchor of anchors) {
|
||||
assert.equal(anchor.target, '_blank');
|
||||
assert.equal(anchor.target, '_blank');
|
||||
}
|
||||
```
|
||||
|
||||
The links on the page should have no underline by default.
|
||||
|
||||
```js
|
||||
assert(new __helpers.CSSHelp(document).getStyle('a.sub-item-link')?.textDecoration === 'none' || new __helpers.CSSHelp(document).getStyle('a')?.textDecoration === 'none' || new __helpers.CSSHelp(document).getStyle('.sub-item-link')?.textDecoration === 'none' );
|
||||
|
||||
assert.isTrue(
|
||||
new __helpers.CSSHelp(document).getStyle('a.sub-item-link')
|
||||
?.textDecoration === 'none' ||
|
||||
new __helpers.CSSHelp(document).getStyle('a')?.textDecoration === 'none' ||
|
||||
new __helpers.CSSHelp(document).getStyle('.sub-item-link')
|
||||
?.textDecoration === 'none'
|
||||
);
|
||||
```
|
||||
|
||||
The links should change color when hovered over.
|
||||
|
||||
```js
|
||||
assert(new __helpers.CSSHelp(document).getStyle('.sub-item-link:hover')?.color || new __helpers.CSSHelp(document).getStyle('a:hover')?.color || new __helpers.CSSHelp(document).getStyle('a.sub-item-link:hover')?.color);
|
||||
assert.exists(
|
||||
new __helpers.CSSHelp(document).getStyle('.sub-item-link:hover')?.color ||
|
||||
new __helpers.CSSHelp(document).getStyle('a:hover')?.color ||
|
||||
new __helpers.CSSHelp(document).getStyle('a.sub-item-link:hover')?.color
|
||||
);
|
||||
```
|
||||
|
||||
The links should change color when they are being clicked.
|
||||
|
||||
```js
|
||||
assert(new __helpers.CSSHelp(document).getStyle('.sub-item-link:active')?.color || new __helpers.CSSHelp(document).getStyle('a:active')?.color || new __helpers.CSSHelp(document).getStyle('a.sub-item-link:active')?.color);
|
||||
assert.exists(
|
||||
new __helpers.CSSHelp(document).getStyle('.sub-item-link:active')?.color ||
|
||||
new __helpers.CSSHelp(document).getStyle('a:active')?.color ||
|
||||
new __helpers.CSSHelp(document).getStyle('a.sub-item-link:active')?.color
|
||||
);
|
||||
```
|
||||
|
||||
The links should have an outline when focused.
|
||||
|
||||
```js
|
||||
assert(new __helpers.CSSHelp(document).getStyle('.sub-item-link:focus')?.outline || new __helpers.CSSHelp(document).getStyle('a:focus')?.outline || new __helpers.CSSHelp(document).getStyle('a.sub-item-link:focus')?.outline);
|
||||
|
||||
assert.exists(
|
||||
new __helpers.CSSHelp(document).getStyle('.sub-item-link:focus')?.outline ||
|
||||
new __helpers.CSSHelp(document).getStyle('a:focus')?.outline ||
|
||||
new __helpers.CSSHelp(document).getStyle('a.sub-item-link:focus')?.outline
|
||||
);
|
||||
```
|
||||
|
||||
The links should change color once visited.
|
||||
|
||||
```js
|
||||
assert(new __helpers.CSSHelp(document).getStyle('.sub-item-link:visited')?.color || new __helpers.CSSHelp(document).getStyle('a:visited')?.color || new __helpers.CSSHelp(document).getStyle('a.sub-item-link:visited')?.color);
|
||||
|
||||
assert.exists(
|
||||
new __helpers.CSSHelp(document).getStyle('.sub-item-link:visited')?.color ||
|
||||
new __helpers.CSSHelp(document).getStyle('a:visited')?.color ||
|
||||
new __helpers.CSSHelp(document).getStyle('a.sub-item-link:visited')?.color
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -197,130 +225,131 @@ assert(new __helpers.CSSHelp(document).getStyle('.sub-item-link:visited')?.color
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Styled To-Do List</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>My To-Do List</h1>
|
||||
<ul class="todo-list">
|
||||
<h1>My To-Do List</h1>
|
||||
<ul class="todo-list">
|
||||
<li>
|
||||
<input type="checkbox" id="task1" />
|
||||
<label for="task1">Explore gaming keyboards</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<input type="checkbox" id="task1">
|
||||
<label for="task1">Explore gaming keyboards</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<a href="#" target="_blank" class="sub-item-link">Store link</a>
|
||||
</li>
|
||||
</ul>
|
||||
<a href="#" target="_blank" class="sub-item-link">Store link</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<input type="checkbox" id="task2" />
|
||||
<label for="task2">Finish the report</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<input type="checkbox" id="task2">
|
||||
<label for="task2">Finish the report</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<a href="#" target="_blank" class="sub-item-link">Request Access</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<a href="#" target="_blank" class="sub-item-link"
|
||||
>Request Access</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<input type="checkbox" id="task3" />
|
||||
<label for="task3">View Phone's Warranty</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<input type="checkbox" id="task3">
|
||||
<label for="task3">View Phone's Warranty</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<a href="#" target="_blank" class="sub-item-link">View Receipts</a>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
<a href="#" target="_blank" class="sub-item-link"
|
||||
>View Receipts</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<input type="checkbox" id="task4" />
|
||||
<label for="task4">Check Processor Specs</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<input type="checkbox" id="task4">
|
||||
<label for="task4">Check Processor Specs</label>
|
||||
<ul class="sub-item">
|
||||
<li>
|
||||
<a href="#" target="_blank" class="sub-item-link">View Model Number</a>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
<a href="#" target="_blank" class="sub-item-link"
|
||||
>View Model Number</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.todo-list {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.todo-list li {
|
||||
margin-bottom: 15px;
|
||||
line-height: 1.6;
|
||||
padding: 10px;
|
||||
background-color: #e5f1e5;
|
||||
border-radius: 10px;
|
||||
position: relative;
|
||||
margin-bottom: 15px;
|
||||
line-height: 1.6;
|
||||
padding: 10px;
|
||||
background-color: #e5f1e5;
|
||||
border-radius: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
a.sub-item-link {
|
||||
margin-left: 10px;
|
||||
text-decoration: none;
|
||||
margin-left: 10px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sub-item-link:link {
|
||||
color: blue;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.sub-item-link:visited {
|
||||
color: purple;
|
||||
color: purple;
|
||||
}
|
||||
|
||||
.sub-item-link:hover {
|
||||
color: red;
|
||||
color: red;
|
||||
}
|
||||
|
||||
.sub-item-link:focus {
|
||||
outline: 2px solid blue;
|
||||
outline-offset: 2px;
|
||||
outline: 2px solid blue;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.sub-item-link:active {
|
||||
color: green;
|
||||
color: green;
|
||||
}
|
||||
|
||||
.sub-item {
|
||||
list-style-type: square;
|
||||
list-style-type: square;
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user