chore: seed chinese traditional (#42005)

Seeds the chinese traditional files manually so we can deploy to
staging.
This commit is contained in:
Nicholas Carrigan (he/him)
2021-05-05 10:13:49 -07:00
committed by GitHub
parent e46e80e08f
commit 3da4be21bb
1669 changed files with 153114 additions and 678 deletions

View File

@ -0,0 +1,46 @@
---
id: 587d774c367417b2b2512a9c
title: 爲視覺障礙用戶添加替代圖像的文本
challengeType: 0
videoUrl: 'https://scrimba.com/c/cPp7VfD'
forumTopicId: 16628
dashedName: add-a-text-alternative-to-images-for-visually-impaired-accessibility
---
# --description--
在其他挑戰裏你應該已經見到過 `img` 標籤的 `alt` 屬性了。 `alt` 屬性中的文本來描述圖片內容,作爲備用文字。 `alt` 屬性可以幫助用戶在圖片加載失敗或者不可見的情況下理解圖片內容, 搜索引擎也通過它來理解圖片內容,並將其加入到搜索結果中。 例如:
```html
<img src="importantLogo.jpeg" alt="Company logo">
```
視覺障礙用戶無法通過視覺獲取信息,而是通過屏幕閱讀器將網頁內容轉換爲音頻以獲取信息。 他們無法通過直觀的呈現理解信息。 屏幕閱讀器可以識別 `alt` 屬性,朗讀其中的內容,來告知用戶圖片包含的關鍵信息。
`alt` 文本可以爲屏幕閱讀器提供圖片的描述信息, 所以你應始終爲圖片添加 `alt` 屬性。 另外,根據最新的 HTML5 標準,爲圖片添加這個屬性是必須的。
# --instructions--
碰巧Camper Cat 是忍者中寫代碼最厲害的,他正在建立一個可以分享忍者知識的網站。 他打算使用的個人資料圖片可以展示他的技能,且應得到所有網站訪問者的讚賞。 請給 `img` 標籤添加一個 `alt` 屬性,說明 Camper Cat 正在學習空手道 (圖片的 `src` 屬性指向的是一個不存在的文件,因此你會看到 `alt` 屬性中的文本出現在頁面上)
# --hints--
`img` 標籤應該包含一個非空的 `alt` 屬性。
```js
assert($('img').attr('alt'));
```
# --seed--
## --seed-contents--
```html
<img src="doingKarateWow.jpeg">
```
# --solutions--
```html
<img src="doingKarateWow.jpeg" alt="Someone doing karate">
```

View File

@ -0,0 +1,105 @@
---
id: 587d778b367417b2b2512aa8
title: 添加可訪問的日期選擇器
challengeType: 0
videoUrl: 'https://scrimba.com/c/cR3bRbCV'
forumTopicId: 301008
dashedName: add-an-accessible-date-picker
---
# --description--
表單中經常出現 `input` 標籤,它可以用來創建多種表單控件。 它的 `type` 屬性指定了所要創建的 `input` 標籤類型。
在以前的挑戰中,我們已經見過 `text``submit` 類型的 input 標籤。 HTML5 規範添加了 `date` 類型來創建日期選擇器。 如果瀏覽器支持,在點擊 `input` 標籤時,日期選擇器會顯示出來,這讓用戶填寫表單變得更加容易。
對於較老的瀏覽器,類型將默認爲 `text` 這樣它可以通過 `label``placeholder` 文本向用戶顯示預期的日期格式。
舉個例子:
```html
<label for="input1">Enter a date:</label>
<input type="date" id="input1" name="input1">
```
# --instructions--
Camper Cat 想舉辦一場比武大會,他想收集參賽者的最佳參賽時間。 請爲 Camper Cat 的頁面添加一個`input` 標籤,起 `type` 屬性值爲 `date``id` 屬性爲 `pickdate``name` 屬性爲 `date`
# --hints--
日期選擇器應有一個 `input` 標籤。
```js
assert($('input').length == 2);
```
`input` 標籤應有一個值爲 `date``type` 屬性。
```js
assert($('input').attr('type') == 'date');
```
`input` 標籤應有一個值爲 `pickdate``id` 屬性。
```js
assert($('input').attr('id') == 'pickdate');
```
`input` 標籤應有一個值爲 `date``name` 屬性。
```js
assert($('input').attr('name') == 'date');
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Tournaments</h1>
</header>
<main>
<section>
<h2>Mortal Kombat Tournament Survey</h2>
<form>
<p>Tell us the best date for the competition</p>
<label for="pickdate">Preferred Date:</label>
<!-- Only change code below this line -->
<!-- Only change code above this line -->
<input type="submit" name="submit" value="Submit">
</form>
</section>
</main>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Tournaments</h1>
</header>
<main>
<section>
<h2>Mortal Kombat Tournament Survey</h2>
<form>
<p>Tell us the best date for the competition</p>
<label for="pickdate">Preferred Date:</label>
<input type="date" id="pickdate" name="date">
<input type="submit" name="submit" value="Submit">
</form>
</section>
</main>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,74 @@
---
id: 587d778f367417b2b2512aad
title: >-
考慮色盲用戶的需求仔細選擇傳達信息的顏色
challengeType: 0
videoUrl: 'https://scrimba.com/c/c437as3'
forumTopicId: 301011
dashedName: >-
avoid-colorblindness-issues-by-carefully-choosing-colors-that-convey-information
---
# --description--
色盲的形式有很多種, 它的表現可以從對特定波長光波的感知度較低,到完全無法看到顏色。 最常見的形式是對綠色的低感知度。
例如,如果內容的前景色與背景色是兩種相近的綠色,那麼色盲用戶可能會無法區分它們。 色輪上距離較近的顏色,特別是相鄰的顏色,看起來都會很難區分。 在表示重要信息的時候應避免使用這類相近顏色的組合。
**注意:**一些在線顏色選擇器有色盲模擬功能,可以模擬顏色在不同形式的色盲中所呈現的效果。 它們和在線對比度檢查器一樣,都是很好的工具。
# --instructions--
Camper Cat 正在測試一個重要按鈕的不同樣式。 在色輪上,用於 `background-color` 的黃色(`#FFFF33`)和用於 `color` 的綠色(`#33FF33`)是相鄰的色調,一些色盲用戶幾乎無法區分它們 (而且這兩個顏色的亮度相近,對比度太小。) 爲了解決這兩個問題,請將文本的 `color` 修改爲深藍色(`#003366`)。
# --hints--
`button` 內容文本的 `color` 屬性值應爲深藍色。
```js
assert($('button').css('color') == 'rgb(0, 51, 102)');
```
# --seed--
## --seed-contents--
```html
<head>
<style>
button {
color: #33FF33;
background-color: #FFFF33;
font-size: 14px;
padding: 10px;
}
</style>
</head>
<body>
<header>
<h1>Danger!</h1>
</header>
<button>Delete Internet</button>
</body>
```
# --solutions--
```html
<head>
<style>
button {
color: #003366;
background-color: #FFFF33;
font-size: 14px;
padding: 10px;
}
</style>
</head>
<body>
<header>
<h1>Danger!</h1>
</header>
<button>Delete Internet</button>
</body>
```

View File

@ -0,0 +1,84 @@
---
id: 587d778f367417b2b2512aac
title: 考慮色盲用戶的需求設置合適的對比度
challengeType: 0
videoUrl: 'https://scrimba.com/c/cmzMEUw'
forumTopicId: 301012
dashedName: avoid-colorblindness-issues-by-using-sufficient-contrast
---
# --description--
顏色是可視化設計的重要組成部分,但是使用顏色也引入了兩個可訪問性問題。 首先,不能僅僅使用顏色作爲傳達重要信息的唯一方式,因爲屏幕閱讀器無法獲取這些信息。 其次,前景色與背景色需要有足夠的對比度,這樣色盲用戶纔可以區分它們。
在之前的挑戰中,我們用文本備用方案解決了第一個問題。 在上一個挑戰中,我們使用對比度檢測工具解決了第二個問題。 WCAG 建議爲顏色及灰度組合使用 4.5:1 的對比度。
色盲用戶無法將一些顏色與另一些顏色區分出來,這通常是因爲色調,有時候是因爲亮度。 你可能還記得,對比度是用前景色與背景色的相對亮度計算的。
實踐中,在對比度檢測工具的幫助下,我們可以通過將較暗的顏色變暗、將較淡的顏色變淡的方法來使對比度達到 4.5:1。 在色輪中,較暗的顏色通常是藍色、紫色、洋紅和紅色,而較淡的顏色通常是橙色、黃色、綠色和藍綠色。
# --instructions--
Camper Cat 正在嘗試爲他的博客文本與背景配置顏色。 他目前使用的組合是綠色的 `background-color` 與栗色的 `color`,它們的對比度爲 2.5:1。 這樣,通過修改 `hsl()` 屬性的第三個參數,我們可以很輕鬆地調整顏色的亮度。 請將 `background-color` 的亮度從 35% 增加到 55%,將 `color` 的亮度從 20% 減少到 15% 這樣可以使對比度達到 5.9:1。
# --hints--
應將 `color` 屬性的亮度值設置爲 15%。
```js
assert(code.match(/color:\s*?hsl\(0,\s*?55%,\s*?15%\)/gi));
```
應將 `background-color` 屬性的亮度值設置爲 55%。
```js
assert(code.match(/background-color:\s*?hsl\(120,\s*?25%,\s*?55%\)/gi));
```
# --seed--
## --seed-contents--
```html
<head>
<style>
body {
color: hsl(0, 55%, 20%);
background-color: hsl(120, 25%, 35%);
}
</style>
</head>
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2>A Word on the Recent Catnip Doping Scandal</h2>
<p>The influence that catnip has on feline behavior is well-documented, and its use as an herbal supplement in competitive ninja circles remains controversial. Once again, the debate to ban the substance is brought to the public's attention after the high-profile win of Kittytron, a long-time proponent and user of the green stuff, at the Claw of Fury tournament.</p>
<p>As I've stated in the past, I firmly believe a true ninja's skills must come from within, with no external influences. My own catnip use shall continue as purely recreational.</p>
</article>
</body>
```
# --solutions--
```html
<head>
<style>
body {
color: hsl(0, 55%, 15%);
background-color: hsl(120, 25%, 55%);
}
</style>
</head>
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2>A Word on the Recent Catnip Doping Scandal</h2>
<p>The influence that catnip has on feline behavior is well-documented, and its use as an herbal supplement in competitive ninja circles remains controversial. Once again, the debate to ban the substance is brought to the public's attention after the high-profile win of Kittytron, a long-time proponent and user of the green stuff, at the Claw of Fury tournament.</p>
<p>As I've stated in the past, I firmly believe a true ninja's skills must come from within, with no external influences. My own catnip use shall continue as purely recreational.</p>
</article>
</body>
```

View File

@ -0,0 +1,75 @@
---
id: 587d778f367417b2b2512aae
title: 爲鏈接添加描述性的文本
challengeType: 0
videoUrl: 'https://scrimba.com/c/c437DcV'
forumTopicId: 301013
dashedName: give-links-meaning-by-using-descriptive-link-text
---
# --description--
屏幕閱讀器用戶可以選擇其設備讀取的內容的類型, 包括表示“跳轉到”(或“跳過”)的元素,跳轉到主要內容,或者從標題中獲取頁面摘要。 用戶還可以選擇只聽取頁面中的超鏈接內容。
屏幕閱讀器通過閱讀鏈接文本(即 `a` 標籤的內容文本)來完成這個操作。 如果我們只在鏈接中寫上 "click here"(點擊這裏)或者 "read more"(閱讀更多),顯然幫助有限。 相反地,應該在 `a` 標籤中使用簡潔的描述性語言來爲用戶提供更多的信息。
# --instructions--
Camper Cat 在鏈接中使用的文本在脫離上下文的情況下,描述性不是很好。 請修改錨點標籤(`a`),將其包含的文本從 `Click here` 改爲 `information about batteries`
# --hints--
應修改 `a` 標籤,將其包含的文本從 `Click here` 改爲 `information about batteries`
```js
assert(
$('a')
.text()
.match(/^(information about batteries)$/g)
);
```
`a` 元素應該有一個 `href` 屬性,且其屬性值爲空字符串 `""`
```js
assert($('a').attr('href') === '');
```
`a` 元素應該有一個結束標籤。
```js
assert(
code.match(/<\/a>/g) &&
code.match(/<\/a>/g).length === code.match(/<a href=(''|"")>/g).length
);
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near. <a href="">Click here</a> for information about batteries</p>
</article>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near. Click here for <a href="">information about batteries</a></p>
</article>
</body>
```

View File

@ -0,0 +1,115 @@
---
id: 587d7789367417b2b2512aa4
title: 使用 audio 元素提高音頻內容的可訪問性
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJVkcZ'
forumTopicId: 301014
dashedName: improve-accessibility-of-audio-content-with-the-audio-element
---
# --description--
HTML5 的 `audio` 標籤用於呈現音頻內容或音頻流,它也具有語義化特性。 音頻內容也需要備用文本,供聾啞人或聽力困難的人使用。 這可以通過頁面上的文本或與字幕鏈接來實現。
`audio` 標籤支持 `controls` 屬性, 用於顯示瀏覽器默認播放、停止和其他控制,以及支持鍵盤功能。 這是一個布爾值屬性,意味着它不需要一個值,它在標籤上存在即開啓設置。
舉個例子:
```html
<audio id="meowClip" controls>
<source src="audio/meow.mp3" type="audio/mpeg">
<source src="audio/meow.ogg" type="audio/ogg">
</audio>
```
**注意:**多媒體內容通常同時包含音頻與視頻部分, 它需要同步的字幕,使視覺或聽覺障礙用戶可以獲取它的內容。 一般情況下,網頁開發者不負責創建字幕或逐字稿,但是需要將它們添加到多媒體中。
# --instructions--
是時候讓 Camper Cat 休息一下,並與朋友 Zersiax (@zersiax) 會面了。 Zersiax 是一位屏幕閱讀器用戶,同時也是無障礙設計的高手。 爲了體驗屏幕閱讀器的朗讀效果,請在 `p` 標籤之後添加一個 `audio` 標籤, 具有 `controls` 屬性。 然後在 `audio` 標籤裏面放一個帶有 `src` 屬性的 `source` 標籤,屬性值爲 `https://s3.amazonaws.com/freecodecamp/screen-reader.mp3`。將 `type` 屬性設置爲 `"audio/mpeg"`.
**注意:**音頻片段的播放速度可能會快到令我們難以理解,但是對於屏幕閱讀器用戶來說這是正常速度。
# --hints--
應該包含一個 `audio` 標籤。
```js
assert($('audio').length === 1);
```
確保 `audio` 元素有結束標籤。
```js
assert(
code.match(/<\/audio>/g).length === 1 &&
code.match(/<audio.*>[\s\S]*<\/audio>/g)
);
```
`audio` 標籤應存在 `controls` 屬性。
```js
assert($('audio').attr('controls'));
```
代碼中應存在 `source` 標籤。
```js
assert($('source').length === 1);
```
`source` 標籤應位於 `audio` 標籤中。
```js
assert($('audio').children('source').length === 1);
```
`source` 標籤中 `src` 的屬性值應該與教程中的鏈接一致。
```js
assert(
$('source').attr('src') ===
'https://s3.amazonaws.com/freecodecamp/screen-reader.mp3'
);
```
`source` 標籤中應具有 `type` 屬性,其屬性值應爲 audio/mpeg。
```js
assert($('source').attr('type') === 'audio/mpeg');
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Real Coding Ninjas</h1>
</header>
<main>
<p>A sound clip of Zersiax's screen reader in action.</p>
</main>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Real Coding Ninjas</h1>
</header>
<main>
<p>A sound clip of Zersiax's screen reader in action.</p>
<audio controls>
<source src="https://s3.amazonaws.com/freecodecamp/screen-reader.mp3" type="audio/mpeg"/>
</audio>
</main>
</body>
```

View File

@ -0,0 +1,161 @@
---
id: 587d778a367417b2b2512aa5
title: 使用 figure 元素提高圖表的可訪問性
challengeType: 0
videoUrl: 'https://scrimba.com/c/cGJMqtE'
forumTopicId: 301015
dashedName: improve-chart-accessibility-with-the-figure-element
---
# --description--
HTML5 引入了 `figure` 標籤以及與之相關的 `figcaption` 標籤。 它們一起用於展示可視化信息(如:圖片、圖表)及其標題。 這樣通過語義化對內容進行分組並配以用於解釋 `figure` 的文字,可以極大地提升內容的可訪問性。
對於圖表之類的可視化數據,標題可以爲屏幕閱讀器用戶提供簡要的說明。 但是這裏有一個難點,如何爲屏幕閱讀器用戶展示那些超出屏幕可視範圍(使用 CSS的表格所表現的圖表數據。
舉個例子,注意 `figcaption` 包含在 `figure` 標籤中,並且可以與其他標籤組合使用:
```html
<figure>
<img src="roundhouseDestruction.jpeg" alt="Photo of Camper Cat executing a roundhouse kick">
<br>
<figcaption>
Master Camper Cat demonstrates proper form of a roundhouse kick.
</figcaption>
</figure>
```
# --instructions--
Camper Cat 正在努力創建一張條形圖,用來顯示每週用於隱形、戰鬥、武器訓練的時間。 請幫助完善他的頁面,將他用於呈現圖表的 `div` 標籤修改爲 `figure` 標籤;將用於呈現圖表標題的 `p` 標籤改爲 `figcaption` 標籤。
# --hints--
應存在一個 `figure` 標籤。
```js
assert($('figure').length == 1);
```
應存在一個 `figcaption` 標籤。
```js
assert($('figcaption').length == 1);
```
不應存在 `div` 標籤。
```js
assert($('div').length == 0);
```
不應存在 `p` 標籤。
```js
assert($('p').length == 0);
```
`figcaption` 應爲 `figure` 的子標籤。
```js
assert($('figure').children('figcaption').length == 1);
```
確保 `figure` 元素有結束標籤。
```js
assert(
code.match(/<\/figure>/g) &&
code.match(/<\/figure>/g).length === code.match(/<figure>/g).length
);
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Training</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<main>
<section>
<!-- Only change code below this line -->
<div>
<!-- Stacked bar chart will go here -->
<br>
<p>Breakdown per week of time to spend training in stealth, combat, and weapons.</p>
</div>
<!-- Only change code above this line -->
</section>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Training</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<main>
<section>
<figure>
<!-- Stacked bar chart will go here -->
<br>
<figcaption>Breakdown per week of time to spend training in stealth, combat, and weapons.</figcaption>
</figure>
</section>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,119 @@
---
id: 587d778a367417b2b2512aa6
title: 使用 label 元素提高表單的可訪問性
challengeType: 0
videoUrl: 'https://scrimba.com/c/cGJMMAN'
forumTopicId: 301016
dashedName: improve-form-field-accessibility-with-the-label-element
---
# --description--
合理地使用語義化的 HTML 標籤和屬性可以提升頁面可訪問性。 在接下來的挑戰中,你將會看到在表單中使用屬性的場景。
`label` 標籤的文本內容通常會是表單組件的名稱或標籤。 這些文本表明了組件的意義,也提升了表單的可訪問性。 `label` 標籤的 `for` 屬性將標籤與表單組件綁定;同時,屏幕閱讀器也會讀取 `for` 屬性的屬性值。
在 HTML 基礎章節中,我們已經學習使用了單選按鈕標籤。 在那個挑戰中,爲了讓標籤可以在點擊的時候也選中輸入框,我們將單選按鈕 input 標籤嵌套在了 `label` 標籤裏面。 在本節課程中,我們介紹了另外一種實現這個功能的方法,那就是使用 `for` 屬性。
`for` 的屬性值必須與表單組件的 `id` 屬性值相同。 舉個例子:
```html
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
</form>
```
# --instructions--
Camper Cat 覺得他的博客文章會有很多人訂閱,因此他想添加一個電子郵件註冊表單。 請爲表示電子郵件的 `label` 標籤添加 `for` 屬性,並將其屬性值設置爲與 `input` 標籤的 `id` 屬性值相同。
# --hints--
`label`標籤應該有一個非空的 `for` 屬性。
```js
assert($('label').attr('for'));
```
`for` 的屬性值應與用於輸入郵箱的 `input` 標籤 `id` 屬性值相同。
```js
assert($('label').attr('for') == 'email');
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<section>
<form>
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
<label>Email:</label>
<input type="text" id="email" name="email">
<input type="submit" name="submit" value="Submit">
</form>
</section>
<article>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<section>
<form>
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
<label for="email">Email:</label>
<input type="text" id="email" name="email">
<input type="submit" name="submit" value="Submit">
</form>
</section>
<article>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,80 @@
---
id: 587d778e367417b2b2512aab
title: 使用高對比度文本提高可讀性
challengeType: 0
videoUrl: 'https://scrimba.com/c/cKb3nCq'
forumTopicId: 301017
dashedName: improve-readability-with-high-contrast-text
---
# --description--
低對比度的前景色與背景色會使文本難以閱讀。 足夠的對比度可以提高內容的可讀性,但是怎樣的對比度纔算是“足夠”的?
Web 內容無障礙指南WCAG建議正常文本的對比度至少爲 4.5 : 1。 對比度是通過比較兩種顏色的相對亮度值來計算的。 對比度的範圍是從相同顏色的 1:1無對比度到白色與黑色的最高對比度 21:1。 在線可用的對比檢查工具很多,可以計算這個比率。
# --instructions--
Camper Cat 爲他的博客選擇了白色背景和淺灰色文字,對比度爲 1.5:1這使博客文章難以閱讀。 請將文字的 `color` 從當前的淺灰色(`#D3D3D3`)修改爲深灰色(`#636363`),以使對比度提升到 6:1。
# --hints--
應該將 `body``color` 修改爲深灰色。
```js
assert($('body').css('color') == 'rgb(99, 99, 99)');
```
不應修改 `body``background-color`
```js
assert($('body').css('background-color') == 'rgb(255, 255, 255)');
```
# --seed--
## --seed-contents--
```html
<head>
<style>
body {
color: #D3D3D3;
background-color: #FFF;
}
</style>
</head>
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2>A Word on the Recent Catnip Doping Scandal</h2>
<p>The influence that catnip has on feline behavior is well-documented, and its use as an herbal supplement in competitive ninja circles remains controversial. Once again, the debate to ban the substance is brought to the public's attention after the high-profile win of Kittytron, a long-time proponent and user of the green stuff, at the Claw of Fury tournament.</p>
<p>As I've stated in the past, I firmly believe a true ninja's skills must come from within, with no external influences. My own catnip use shall continue as purely recreational.</p>
</article>
</body>
```
# --solutions--
```html
<head>
<style>
body {
color: #636363;
background-color: #FFF;
}
</style>
</head>
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2>A Word on the Recent Catnip Doping Scandal</h2>
<p>The influence that catnip has on feline behavior is well-documented, and its use as an herbal supplement in competitive ninja circles remains controversial. Once again, the debate to ban the substance is brought to the public's attention after the high-profile win of Kittytron, a long-time proponent and user of the green stuff, at the Claw of Fury tournament.</p>
<p>As I've stated in the past, I firmly believe a true ninja's skills must come from within, with no external influences. My own catnip use shall continue as purely recreational.</p>
</article>
</body>
```

View File

@ -0,0 +1,62 @@
---
id: 587d774e367417b2b2512a9f
title: 使用 main 元素包裹主題內容
challengeType: 0
videoUrl: 'https://scrimba.com/c/cPp7zuE'
forumTopicId: 301018
dashedName: jump-straight-to-the-content-using-the-main-element
---
# --description--
HTML5 引入了一些新元素,給予開發者更多的選擇,也包含輔助功能。 HTML5 引入了諸如 `main``header``footer``nav``article``section` 等大量新標籤。
默認情況下,瀏覽器呈現這些元素的方式類似於普通的 `div`。 但是,在適當的地方使用它們會讓標記文本具有更多的含義。 僅標籤名稱就可以表示它所包含的信息類型,這給內容增加了語義含義。 輔助技術可以獲取這種信息,爲用戶提供更好的頁面摘要或導航選項。
`main` 標籤用於呈現網頁的主體內容,且每個頁面應只有一個。 這是爲了圍繞與頁面中心主題相關的信息, 而不應包含如導航連接、網頁橫幅等需要在多個頁面中重複出現的內容。
`main` 標籤也有一個內嵌的特性,以便輔助技術快速定位到頁面的主體。 如果你在頁面頂部看到過“跳轉到主要內容”鏈接,那麼使用 `main` 標籤會自動讓輔助設備具有這個跳轉的功能。
# --instructions--
Camper Cat 對他的忍者武器頁面有一些新的想法。 請幫他在 `header` 標籤和 `footer` 標籤(在接下來的挑戰中會詳細介紹)之間添加一個有開始和結束標記的 `main` 標籤。 現在保持 `main` 標籤爲空。
# --hints--
應存在一個 `main` 標籤。
```js
assert($('main').length == 1);
```
`main` 標籤應位於 `header` 標籤與 `footer` 標籤之間。
```js
assert(code.match(/<\/header>\s*?<main>\s*?<\/main>/gi));
```
# --seed--
## --seed-contents--
```html
<header>
<h1>Weapons of the Ninja</h1>
</header>
<footer></footer>
```
# --solutions--
```html
<header>
<h1>Weapons of the Ninja</h1>
</header>
<main>
</main>
<footer></footer>
```

View File

@ -0,0 +1,76 @@
---
id: 587d774c367417b2b2512a9d
title: 瞭解 Alt 文本留空的情景
challengeType: 0
videoUrl: 'https://scrimba.com/c/cM9P4t2'
forumTopicId: 301019
dashedName: know-when-alt-text-should-be-left-blank
---
# --description--
在上一個挑戰中,我們瞭解到 `img` 標籤必須有一個 `alt` 屬性。 但是,有時圖像通過它們的描述文本被歸類,或者只用於裝飾。 在這些情況下, `alt` 文本可能是多餘的或沒有必要的。
在圖片已經有了文字說明,或者僅僅爲了美化頁面的情況下,`img` 仍然需要一個 `alt` 屬性,但可以設置爲空字符串。 例如:
```html
<img src="visualDecoration.jpeg" alt="">
```
比如,背景圖片通常起裝飾作用。 但這些圖片通常都是通過 CSS 規則而非 HTML 引入的,因此屏幕閱讀器毋需讀取。
**注意:**對於有標題的圖片,依然需要添加 `alt` 文本,因爲這樣有助於搜索引擎記錄圖片內容。
# --instructions--
Camper Cat 已經大體寫好了博客頁面。 他打算在他的兩篇文章之間添加一個武士劍裝飾圖片,作爲兩篇文章之間的分割線。 爲 `img` 標籤添加 `alt` 屬性,把它的屬性值設爲空 (注意:這裏圖片的 `src` 屬性提供的鏈接是無效的,因此頁面上不會顯示任何武士刀的圖片,不用擔心)。
# --hints--
`img` 標籤應具有 `alt` 屬性。
```js
assert(!($('img').attr('alt') == undefined));
```
`alt` 的屬性值應爲空。
```js
assert($('img').attr('alt') == '');
```
# --seed--
## --seed-contents--
```html
<h1>Deep Thoughts with Master Camper Cat</h1>
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>To Come...</p>
</article>
<img src="samuraiSwords.jpeg">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>To Come...</p>
</article>
```
# --solutions--
```html
<h1>Deep Thoughts with Master Camper Cat</h1>
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>To Come...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>To Come...</p>
</article>
```

View File

@ -0,0 +1,244 @@
---
id: 587d778d367417b2b2512aaa
title: 使用自定義 CSS 讓元素僅對屏幕閱讀器可見
challengeType: 0
videoUrl: 'https://scrimba.com/c/cJ8QGkhJ'
forumTopicId: 301020
dashedName: make-elements-only-visible-to-a-screen-reader-by-using-custom-css
---
# --description--
到目前爲止,所有關於可訪問性的挑戰都沒有使用 CSS。 這是爲了在介紹視覺設計方面之前強調使用邏輯結構和有語義意義的標籤的重要性。
但如果我們想在頁面中添加一些只對屏幕閱讀器可見的內容,可以用 CSS 來實現。 當信息爲視覺格式(例如圖表)時,但屏幕閱讀器用戶需要備用文稿(例如表格)來訪問數據,在這種情況下, 使用 CSS 將屏幕的只讀元素放到瀏覽器窗口可視區域之外。
舉個例子:
```css
.sr-only {
position: absolute;
left: -10000px;
width: 1px;
height: 1px;
top: auto;
overflow: hidden;
}
```
**注意:**以下的 CSS 解決方案與上面的結果不同:
<ul>
<li><code>display: none;</code><code>visibility: hidden;</code> 會把內容徹底隱藏起來,屏幕閱讀器也無法獲取這些內容。</li>
<li>如果把值設置爲 0px<code>width: 0px; height: 0px;</code>,意味着讓元素脫離文檔流,這樣做同樣也會讓屏幕閱讀器忽略此元素。</li>
</ul>
# --instructions--
Camper Cat 爲他的訓練頁面創建了一個十分酷炫的條形圖。 考慮到可訪問性,他還將數據放入到了一個表格中,供屏幕閱讀器用戶使用。 表格已有一個 `sr-only` class但是還沒有添加 CSS 規則。 設置 `position` 的值爲 `absolute``left` 的值爲 `-10000px``width``height` 的值均爲 `1px`
# --hints--
設置 `sr-only` class 的 `position` 屬性值爲 `absolute`
```js
assert($('.sr-only').css('position') == 'absolute');
```
設置 `sr-only` class 的 `left` 屬性值爲`-10000px`
```js
assert($('.sr-only').css('left') == '-10000px');
```
設置 `sr-only` class 的 `width` 屬性值爲 `1` 像素。
```js
assert(code.match(/width:\s*?1px/gi));
```
設置 `sr-only` class 的 `height` 屬性值爲 `1` 像素。
```js
assert(code.match(/height:\s*?1px/gi));
```
# --seed--
## --seed-contents--
```html
<head>
<style>
.sr-only {
position: ;
left: ;
width: ;
height: ;
top: auto;
overflow: hidden;
}
</style>
</head>
<body>
<header>
<h1>Training</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<section>
<h2>Master Camper Cat's Beginner Three Week Training Program</h2>
<figure>
<!-- Stacked bar chart of weekly training -->
<p>[Stacked bar chart]</p>
<br />
<figcaption>Breakdown per week of time to spend training in stealth, combat, and weapons.</figcaption>
</figure>
<table class="sr-only">
<caption>Hours of Weekly Training in Stealth, Combat, and Weapons</caption>
<thead>
<tr>
<th></th>
<th scope="col">Stealth &amp; Agility</th>
<th scope="col">Combat</th>
<th scope="col">Weapons</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Week One</th>
<td>3</td>
<td>5</td>
<td>2</td>
<td>10</td>
</tr>
<tr>
<th scope="row">Week Two</th>
<td>4</td>
<td>5</td>
<td>3</td>
<td>12</td>
</tr>
<tr>
<th scope="row">Week Three</th>
<td>4</td>
<td>6</td>
<td>3</td>
<td>13</td>
</tr>
</tbody>
</table>
</section>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye, world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<head>
<style>
.sr-only {
position: absolute;
left: -10000px;
width: 1px;
height: 1px;
top: auto;
overflow: hidden;
}
</style>
</head>
<body>
<header>
<h1>Training</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<section>
<h2>Master Camper Cat's Beginner Three Week Training Program</h2>
<figure>
<!-- Stacked bar chart of weekly training -->
<p>[Stacked bar chart]</p>
<br />
<figcaption>Breakdown per week of time to spend training in stealth, combat, and weapons.</figcaption>
</figure>
<table class="sr-only">
<caption>Hours of Weekly Training in Stealth, Combat, and Weapons</caption>
<thead>
<tr>
<th></th>
<th scope="col">Stealth &amp; Agility</th>
<th scope="col">Combat</th>
<th scope="col">Weapons</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Week One</th>
<td>3</td>
<td>5</td>
<td>2</td>
<td>10</td>
</tr>
<tr>
<th scope="row">Week Two</th>
<td>4</td>
<td>5</td>
<td>3</td>
<td>12</td>
</tr>
<tr>
<th scope="row">Week Three</th>
<td>4</td>
<td>6</td>
<td>3</td>
<td>13</td>
</tr>
</tbody>
</table>
</section>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye, world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,106 @@
---
id: 587d7790367417b2b2512aaf
title: 通過給元素添加 accesskey 屬性來讓用戶可以在鏈接之間快速導航
challengeType: 0
videoUrl: 'https://scrimba.com/c/cQvmaTp'
forumTopicId: 301021
dashedName: make-links-navigable-with-html-access-keys
---
# --description--
HTML 提供 `accesskey` 屬性,用於指定激活元素或者使元素獲得焦點的快捷鍵。 添加 `accesskey` 屬性可以讓使用鍵盤的用戶更高效率地導航。
HTML5 允許在任何標籤上使用這個屬性。 該屬性尤其適用於鏈接、按鈕、表單組件等元素。
舉個例子:
```html
<button accesskey="b">Important Button</button>
```
# --instructions--
Camper Cat 希望爲他兩篇博客的標題鏈接設置快捷鍵,以使用戶可以快速導航到文章的全文。 爲兩個鏈接添加一個 `accesskey` 屬性,設置第一個的值爲 `g`(代表 Garfield設置第二的值爲 `c`(代表 Chuck Norris
# --hints--
`id``first``a` 標籤應具有 `accesskey` 屬性。
```js
assert($('#first').attr('accesskey'));
```
`id``second``a` 標籤應具有 `accesskey` 屬性。
```js
assert($('#second').attr('accesskey'));
```
`id``first``a` 標籤的 `accesskey` 屬性值應爲 `g`。 注意要使用小寫。
```js
assert($('#first').attr('accesskey') == 'g');
```
`id``second``a` 標籤的 `accesskey` 屬性值應爲 `c`。 注意使用小寫。
```js
assert($('#second').attr('accesskey') == 'c');
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2><a id="first" href="#">The Garfield Files: Lasagna as Training Fuel?</a></h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<article>
<h2><a id="second" href="#">Is Chuck Norris a Cat Person?</a></h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<article>
<h2><a id="first" accesskey="g" href="#">The Garfield Files: Lasagna as Training Fuel?</a></h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<article>
<h2><a id="second" accesskey="c" href="#">Is Chuck Norris a Cat Person?</a></h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,116 @@
---
id: 587d7788367417b2b2512aa3
title: 使用 footer 元素來讓屏幕閱讀器更容易進行導航
challengeType: 0
videoUrl: 'https://scrimba.com/c/crVrDh8'
forumTopicId: 301022
dashedName: make-screen-reader-navigation-easier-with-the-footer-landmark
---
# --description--
`header``nav` 類似,`footer` 元素也具有語義化的特性,可以讓輔助工具快速定位到它。 它位於頁面底部,用於呈現版權信息或者相關文檔鏈接。
# --instructions--
Camper Cat 的忍者訓練頁面進展順利。 請將他在頁面底部呈現版權信息的 `div` 元素更改爲 `footer` 元素。
# --hints--
應存在一個 `footer` 標籤。
```js
assert($('footer').length == 1);
```
不應存在 `div` 標籤。
```js
assert($('div').length == 0);
```
確保 `footer` 元素有結束標籤。
```js
assert(code.match(/<footer>\s*&copy; 2018 Camper Cat\s*<\/footer>/g));
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Training</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<main>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
<div>&copy; 2018 Camper Cat</div>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Training</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<main>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,111 @@
---
id: 587d7787367417b2b2512aa1
title: 使用 header 元素來讓屏幕閱讀器更容易進行導航
challengeType: 0
videoUrl: 'https://scrimba.com/c/cB76vtv'
forumTopicId: 301023
dashedName: make-screen-reader-navigation-easier-with-the-header-landmark
---
# --description--
`header` 也是一個具有語義化的、可以提升頁面可訪問性的 HTML5 標籤。 它可以爲父級標籤呈現簡介信息或者導航鏈接,適用於那些在多個頁面頂部重複出現的內容。
`main` 類似,`header` 的語義化特性也可以讓輔助工具快速定位到它的內容。
**注意:**`header` 應當在 HTML 文檔的 `body` 標籤內使用。 它與包含頁面標題、元信息的 `head` 標籤不同。
# --instructions--
Camper Cat 正在創作一些訓練忍者的精彩文章,並打算爲這些文章創建一個新的頁面。 請把包含 `h1``div` 標籤替換爲 `header` 標籤。
# --hints--
應該存在一個 `header` 標籤。
```js
assert($('header').length == 1);
```
`header` 標籤中應包含 `h1`
```js
assert($('header').children('h1').length == 1);
```
不應存在 `div` 標籤。
```js
assert($('div').length == 0);
```
確保 `header` 標籤是閉合的。
```js
assert(
code.match(/<\/header>/g) &&
code.match(/<\/header>/g).length === code.match(/<header>/g).length
);
```
# --seed--
## --seed-contents--
```html
<body>
<div>
<h1>Training with Camper Cat</h1>
</div>
<main>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Training with Camper Cat</h1>
</header>
<main>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
</body>
```

View File

@ -0,0 +1,121 @@
---
id: 587d7788367417b2b2512aa2
title: 使用 nav 元素使屏幕閱讀器更容易導航
challengeType: 0
videoUrl: 'https://scrimba.com/c/czVwWSv'
forumTopicId: 301024
dashedName: make-screen-reader-navigation-easier-with-the-nav-landmark
---
# --description--
`nav` 也是一個具有語義化特性的 HTML5 標籤,它可以使屏幕閱讀器快速識別出頁面中的導航信息。 它用於呈現頁面中的主導航鏈接。
對於在多個頁面底部出現的站點鏈接,我們不需要使用 `nav` 標籤。 我們將會在下個挑戰中學習 `footer` 標籤的使用。
# --instructions--
Camper Cat 在他的忍者訓練頁面頂端放置了多個導航鏈接,但這些鏈接都寫在了 `div` 中。 請將 `div` 標籤更改爲 `nav` 標籤,以提升頁面的可訪問性。
# --hints--
應存在一個 `nav` 標籤。
```js
assert($('nav').length == 1);
```
`nav` 標籤應包含 `ul` 標籤及其列表項。
```js
assert($('nav').children('ul').length == 1);
```
不應存在 `div` 標籤。
```js
assert($('div').length == 0);
```
確保 `nav` 標籤是閉合的。
```js
assert(
code.match(/<\/nav>/g) &&
code.match(/<\/nav>/g).length === code.match(/<nav>/g).length
);
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Training with Camper Cat</h1>
<div>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</div>
</header>
<main>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Training with Camper Cat</h1>
<nav>
<ul>
<li><a href="#stealth">Stealth &amp; Agility</a></li>
<li><a href="#combat">Combat</a></li>
<li><a href="#weapons">Weapons</a></li>
</ul>
</nav>
</header>
<main>
<section id="stealth">
<h2>Stealth &amp; Agility Training</h2>
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
<article><h3>No training is NP-complete without parkour</h3></article>
</section>
<section id="combat">
<h2>Combat Training</h2>
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
</section>
<section id="weapons">
<h2>Weapons Training</h2>
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
</section>
</main>
</body>
```

View File

@ -0,0 +1,132 @@
---
id: 587d778c367417b2b2512aa9
title: 使用 HTML5 的 datetime 屬性標準化時間
challengeType: 0
videoUrl: 'https://scrimba.com/c/cmzMgtz'
forumTopicId: 301025
dashedName: standardize-times-with-the-html5-datetime-attribute
---
# --description--
繼續日期主題。 HTML5 還引入了 `time` 標籤與 `datetime` 屬性來標準化時間。 `time` 元素是一個行內元素,用於在一個頁面上顯示日期或時間。 `datetime` 屬性包含的有效格式。 輔助設備可以獲取這個值。 這個屬性也有助於避免混亂,因爲它規定了時間的標準化版本,甚至可以在文本中以非正式的方式或學術方式使用它。
舉個例子:
```html
<p>Master Camper Cat officiated the cage match between Goro and Scorpion <time datetime="2013-02-13">last Wednesday</time>, which ended in a draw.</p>
```
# --instructions--
Camper Cat 格鬥的調查結果出來了! 用 `time` 標籤包裹文本 `Thursday, September 15<sup>th</sup>`,添加一個 `datetime` 屬性,將屬性值設置爲 `2016-09-15`
# --hints--
應存在一個 `time` 元素和一個內容文本爲 `Thank you to everyone for responding to Master Camper Cat's survey.``p` 元素。
```js
assert(timeElement.length);
```
`time` 元素的內容文本應爲 `Thursday, September 15<sup>th</sup>`
```js
assert(
timeElement.length &&
$(timeElement).html().trim() === 'Thursday, September 15<sup>th</sup>'
);
```
`time` 元素應包含非空的 `datetime` 屬性。
```js
assert(datetimeAttr && datetimeAttr.length);
```
`datetime` 的屬性值應爲 `2016-09-15`
```js
assert(datetimeAttr === '2016-09-15');
```
# --seed--
## --after-user-code--
```html
<script>
const pElement = $("article > p")
.filter((_, elem) => $(elem).text().includes("Thank you to everyone for responding to Master Camper Cat's survey."));
const timeElement = pElement[0] ? $(pElement[0]).find("time") : null;
const datetimeAttr = $(timeElement).attr("datetime");
</script>
```
## --seed-contents--
```html
<body>
<header>
<h1>Tournaments</h1>
</header>
<article>
<h2>Mortal Kombat Tournament Survey Results</h2>
<!-- Only change code below this line -->
<p>Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is Thursday, September 15<sup>th</sup>. May the best ninja win!</p>
<!-- Only change code above this line -->
<section>
<h3>Comments:</h3>
<article>
<p>Posted by: Sub-Zero on <time datetime="2016-08-13T20:01Z">August 13<sup>th</sup></time></p>
<p>Johnny Cage better be there, I'll finish him!</p>
</article>
<article>
<p>Posted by: Doge on <time datetime="2016-08-15T08:12Z">August 15<sup>th</sup></time></p>
<p>Wow, much combat, so mortal.</p>
</article>
<article>
<p>Posted by: The Grim Reaper on <time datetime="2016-08-16T00:00Z">August 16<sup>th</sup></time></p>
<p>Looks like I'll be busy that day.</p>
</article>
</section>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Tournaments</h1>
</header>
<article>
<h2>Mortal Kombat Tournament Survey Results</h2>
<p>Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is <time datetime="2016-09-15">Thursday, September 15<sup>th</sup></time>. May the best ninja win!</p>
<section>
<h3>Comments:</h3>
<article>
<p>Posted by: Sub-Zero on <time datetime="2016-08-13T20:01Z">August 13<sup>th</sup></time></p>
<p>Johnny Cage better be there, I'll finish him!</p>
</article>
<article>
<p>Posted by: Doge on <time datetime="2016-08-15T08:12Z">August 15<sup>th</sup></time></p>
<p>Wow, much combat, so mortal.</p>
</article>
<article>
<p>Posted by: The Grim Reaper on <time datetime="2016-08-16T00:00Z">August 16<sup>th</sup></time></p>
<p>Looks like I'll be busy that day.</p>
</article>
</section>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,92 @@
---
id: 587d774d367417b2b2512a9e
title: 使用標題顯示內容的層次關係
challengeType: 0
videoUrl: 'https://scrimba.com/c/cqVEktm'
forumTopicId: 301026
dashedName: use-headings-to-show-hierarchical-relationships-of-content
---
# --description--
標題標籤(包括 `h1``h6`)有很高的使用率,它們用於描述內容的主題。 在屏幕閱讀器中,用戶爲了快速瞭解頁面綱要,可以設置讓閱讀器只朗讀頁面標題。 這意味着我們不應僅僅爲了設置不同字號而使用標題,而應讓標籤本身具有語義化和實質性的含義,同時不同標題之間也應關聯(具有層級關係)。
*語義化*的意思是,標籤名能準確地表達它所含內容的信息類型。
如果你正在撰寫帶有導言、主體和結論的論文,在你的概要中把結論作爲主體的一部分是沒有意義的。 結論應該是單獨的一個部分。 類似地,頁面中的標題標籤也應該是有序的,並且能表明內容的層次關係。
在使用中,相同級別(或者更高級別)的標題標籤用於開啓新的章節,低一級別的標題標籤用於開啓上一級標題標籤的子小節。
比如說,如果我們在一個 `h2` 標籤後加上若干由 `h4` 標籤引導的頁面。 此時發生了層級的錯位,這會讓使用屏幕閱讀器的用戶感到困惑。 儘管在瀏覽器所顯示的頁面中,錯誤地使用這六個標題標籤依然可以讓它們在視覺效果上看起來很合理。 但此時,我們應該按照層級正確地使用標籤,然後用 CSS 來調整樣式。
最後一點,每個頁面應只有一個 `h1` 標籤,用來概括說明頁面的主題。 另外,這六個標題標籤可以讓搜索引擎獲取頁面的大綱。
# --instructions--
Camper Cat 希望他的網站有一個介紹如何成爲忍者的頁面。 幫助他修改好標題,以便他的標記使內容具有語義意義,並顯示其章節的父級與子級的關係。 你需要將所有的 `h5` 標題標籤調整爲恰當的級別,來說明它們是 `h2` 標題標籤的子級。 調整爲 `h3` 標籤即可。
# --hints--
應存在 6 個 `h3` 標籤。
```js
assert($('h3').length === 6);
```
確保 `h3` 有結束標籤
```js
assert((code.match(/\/h3/g) || []).length === 6);
```
不應該存在 `h5` 標籤.
```js
assert($('h5').length === 0);
```
不應該存在 `h5` 的結束標籤。
```js
assert(/\/h5/.test(code) === false);
```
# --seed--
## --seed-contents--
```html
<h1>How to Become a Ninja</h1>
<main>
<h2>Learn the Art of Moving Stealthily</h2>
<h5>How to Hide in Plain Sight</h5>
<h5>How to Climb a Wall</h5>
<h2>Learn the Art of Battle</h2>
<h5>How to Strengthen your Body</h5>
<h5>How to Fight like a Ninja</h5>
<h2>Learn the Art of Living with Honor</h2>
<h5>How to Breathe Properly</h5>
<h5>How to Simplify your Life</h5>
</main>
```
# --solutions--
```html
<h1>How to Become a Ninja</h1>
<main>
<h2>Learn the Art of Moving Stealthily</h2>
<h3>How to Hide in Plain Sight</h3>
<h3>How to Climb a Wall</h3>
<h2>Learn the Art of Battle</h2>
<h3>How to Strengthen your Body</h3>
<h3>How to Fight like a Ninja</h3>
<h2>Learn the Art of Living with Honor</h2>
<h3>How to Breathe Properly</h3>
<h3>How to Simplify your Life</h3>
</main>
```

View File

@ -0,0 +1,144 @@
---
id: 587d7790367417b2b2512ab0
title: 使用 tabindex 將鍵盤焦點添加到元素中
challengeType: 0
videoUrl: 'https://scrimba.com/c/cmzMDHW'
forumTopicId: 301027
dashedName: use-tabindex-to-add-keyboard-focus-to-an-element
---
# --description--
HTML 的 `tabindex` 屬性有三種與標籤焦點相關的功能。 當它在一個元素上時,表示該元素可以獲得焦點。 tabindex 的值(可以是零、負整數或正整數)定義了行爲。
當用戶使用鍵盤瀏覽頁面時,諸如鏈接、表單控件等元素可以自動獲得焦點。 它們獲得焦點的順序與它們出現在 HTML 文檔流中的順序一致。 我們可以通過將其他標籤(如 `div``span``p` 等)的 `tabindex` 屬性值設爲 0 來讓它們實現類似的效果。 比如:
```html
<div tabindex="0">I need keyboard focus!</div>
```
**注意:** `tabindex` 屬性值爲負整數(通常爲 -1的標籤也是可以獲得焦點的只是不可以通過鍵盤操作如 tab 鍵)來獲得焦點。 這種方法通常用於以編程的方式使內容獲得焦點(如:將焦點設置到用 `div` 實現的彈出框上)的場景。 只是這部分內容已經超出了當前挑戰的範圍。
# --instructions--
Camper Cat 新建了一個用來收集他的用戶信息的調查。 他知道輸入框可以自動獲得鍵盤焦點但他希望用戶使用鍵盤切換標籤時焦點可以停留在指示文字Instructions上。 請給 `p` 標籤添加一個 `tabindex` 屬性,將屬性值設置爲 `0`。 注意:使用 `tabindex` 屬性還可以讓 CSS 僞類 `:focus``p` 標籤上生效。
# --hints--
表單中作爲指示文字Instructions`p` 標籤應具有 `tabindex` 屬性。
```js
assert($('p').attr('tabindex'));
```
`p` 標籤的 `tabindex` 屬性值應設置爲 0。
```js
assert($('p').attr('tabindex') == '0');
```
# --seed--
## --seed-contents--
```html
<head>
<style>
p:focus {
background-color: yellow;
}
</style>
</head>
<body>
<header>
<h1>Ninja Survey</h1>
</header>
<section>
<form>
<p>Instructions: Fill in ALL your information then click <b>Submit</b></p>
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<fieldset>
<legend>What level ninja are you?</legend>
<input id="newbie" type="radio" name="levels" value="newbie">
<label for="newbie">Newbie Kitten</label><br>
<input id="intermediate" type="radio" name="levels" value="intermediate">
<label for="intermediate">Developing Student</label><br>
<input id="master" type="radio" name="levels" value="master">
<label for="master">9th Life Master</label>
</fieldset>
<br>
<fieldset>
<legend>Select your favorite weapons:</legend>
<input id="stars" type="checkbox" name="weapons" value="stars">
<label for="stars">Throwing Stars</label><br>
<input id="nunchucks" type="checkbox" name="weapons" value="nunchucks">
<label for="nunchucks">Nunchucks</label><br>
<input id="sai" type="checkbox" name="weapons" value="sai">
<label for="sai">Sai Set</label><br>
<input id="sword" type="checkbox" name="weapons" value="sword">
<label for="sword">Sword</label>
</fieldset>
<br>
<input type="submit" name="submit" value="Submit">
</form><br>
</section>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<head>
<style>
p:focus {
background-color: yellow;
}
</style>
</head>
<body>
<header>
<h1>Ninja Survey</h1>
</header>
<section>
<form>
<p tabindex="0">Instructions: Fill in ALL your information then click <b>Submit</b></p>
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<fieldset>
<legend>What level ninja are you?</legend>
<input id="newbie" type="radio" name="levels" value="newbie">
<label for="newbie">Newbie Kitten</label><br>
<input id="intermediate" type="radio" name="levels" value="intermediate">
<label for="intermediate">Developing Student</label><br>
<input id="master" type="radio" name="levels" value="master">
<label for="master">9th Life Master</label>
</fieldset>
<br>
<fieldset>
<legend>Select your favorite weapons:</legend>
<input id="stars" type="checkbox" name="weapons" value="stars">
<label for="stars">Throwing Stars</label><br>
<input id="nunchucks" type="checkbox" name="weapons" value="nunchucks">
<label for="nunchucks">Nunchucks</label><br>
<input id="sai" type="checkbox" name="weapons" value="sai">
<label for="sai">Sai Set</label><br>
<input id="sword" type="checkbox" name="weapons" value="sword">
<label for="sword">Sword</label>
</fieldset>
<br>
<input type="submit" name="submit" value="Submit">
</form><br>
</section>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,160 @@
---
id: 587d7790367417b2b2512ab1
title: 使用 tabindex 指定多個元素的鍵盤焦點順序
challengeType: 0
videoUrl: 'https://scrimba.com/c/cmzRRcb'
forumTopicId: 301028
dashedName: use-tabindex-to-specify-the-order-of-keyboard-focus-for-several-elements
---
# --description--
`tabindex` 屬性還可以指定元素的 tab 鍵焦點順序, 將它的值設置爲大於等於 1 的整數,就可以實現這個功能。
給元素設置 `tabindex="1"`,鍵盤將首先把焦點放在這個元素上。 然後它按照指定的 `tabindex`2、3 等等)順序循環,再移動到默認值和 `tabindex="0"` 項目。
需要注意的是,使用這種方式設置 tab 鍵焦點順序會覆蓋默認順序,其中默認順序爲標籤在文檔流中出現的順序。 這可能會讓那些希望從頁面頂部開始導航的用戶感到困惑。 使用 tabindex 在某些情況下是必要的,但在使用時要充分考慮到頁面的可訪問性。
舉個例子:
```html
<div tabindex="1">I get keyboard focus, and I get it first!</div>
```
```html
<div tabindex="2">I get keyboard focus, and I get it second!</div>
```
# --instructions--
Camper Cat 在他的勵志名言頁面中有一個搜索區域,他打算使用 CSS 把這個區域定位在頁面的右上角。 Camper Cat 希望他的搜索search`input` 與提交submit`input` 表單控件是 tab 鍵焦點順序的前兩項。 請給 `search` `input` 添加 `tabindex` 屬性,將屬性值設置爲 `1`;給 `submit` `input` 添加一個 `tabindex` 屬性,將屬性值設置爲 `2`
另一件需要注意的事情是,單擊元素時,某些瀏覽器可能會將你置於 tab 鍵焦點順序的中間位置。 頁面上已添加一個元素,以確保你始終從 tab 鍵焦點順序的開頭開始。
# --hints--
應給 `search` `input` 標籤添加一個 `tabindex` 屬性。
```js
assert($('#search').attr('tabindex'));
```
應給 `submit` `input` 標籤添加一個 `tabindex` 屬性。
```js
assert($('#submit').attr('tabindex'));
```
`search` `input` 標籤的 `tabindex` 屬性值應爲 1。
```js
assert($('#search').attr('tabindex') == '1');
```
`submit` `input` 標籤的 `tabindex` 屬性值應爲 2。
```js
assert($('#submit').attr('tabindex') == '2');
```
# --seed--
## --seed-contents--
```html
<body>
<div tabindex="1" class="overlay"></div>
<header>
<h1>Even Deeper Thoughts with Master Camper Cat</h1>
<nav>
<ul>
<li><a href="">Home</a></li>
<li><a href="">Blog</a></li>
<li><a href="">Training</a></li>
</ul>
</nav>
</header>
<form>
<label for="search">Search:</label>
<input type="search" name="search" id="search">
<input type="submit" name="submit" value="Submit" id="submit">
</form>
<h2>Inspirational Quotes</h2>
<blockquote>
<p>&ldquo;There's no Theory of Evolution, just a list of creatures I've allowed to live.&rdquo;<br>
- Chuck Norris</p>
</blockquote>
<blockquote>
<p>&ldquo;Wise men say forgiveness is divine, but never pay full price for late pizza.&rdquo;<br>
- TMNT</p>
</blockquote>
<footer>&copy; 2018 Camper Cat</footer>
</body>
<style>
body {
height: 100%;
margin: 0 !important;
padding: 8px;
}
.overlay {
margin: -8px;
position: absolute;
width: 100%;
height: 100%;
}
</style>
```
# --solutions--
```html
<body>
<div tabindex="1" class="overlay"></div>
<header>
<h1>Even Deeper Thoughts with Master Camper Cat</h1>
<nav>
<ul>
<li><a href="">Home</a></li>
<li><a href="">Blog</a></li>
<li><a href="">Training</a></li>
</ul>
</nav>
</header>
<form>
<label for="search">Search:</label>
<input tabindex="1" type="search" name="search" id="search">
<input tabindex="2" type="submit" name="submit" value="Submit" id="submit">
</form>
<h2>Inspirational Quotes</h2>
<blockquote>
<p>&ldquo;There's no Theory of Evolution, just a list of creatures I've allowed to live.&rdquo;<br>
- Chuck Norris</p>
</blockquote>
<blockquote>
<p>&ldquo;Wise men say forgiveness is divine, but never pay full price for late pizza.&rdquo;<br>
- TMNT</p>
</blockquote>
<footer>&copy; 2018 Camper Cat</footer>
</body>
<style>
body {
height: 100%;
margin: 0 !important;
padding: 8px;
}
.overlay {
margin: -8px;
position: absolute;
width: 100%;
height: 100%;
}
</style>
```

View File

@ -0,0 +1,92 @@
---
id: 587d774e367417b2b2512aa0
title: 使用 article 元素包裹文章內容
challengeType: 0
videoUrl: 'https://scrimba.com/c/cPp79S3'
forumTopicId: 301029
dashedName: wrap-content-in-the-article-element
---
# --description--
`article` 是另一個具有語義化特性的 HTML5 新標籤。 `article` 是一個分段標籤,用於呈現獨立及完整的內容。 這個標籤適用於博客、論壇帖子或者新聞文章。
確定內容是否可以單獨作爲一部分,通常是個人的判斷,但你可以使用幾個簡單的測試。 如果刪除了所有周圍的上下文,這個內容是否仍然有意義? 類似地,對於文本內容,可否把這些內容放到一個 RSS 推送裏?
請牢記,輔助設備依賴組織良好、語義化的標籤來獲取頁面中的信息。
**注意:**`section` 元素也是 HTML5 引入的新元素,其語義與 `article` 略有不同。 `article` 用於獨立且完整的內容,而 `section` 用於對與主題相關的內容進行分組。 它們可以根據需要來嵌套使用。 舉個例子:如果一本書是一個 `article` 的話,那麼每個章節就是 `section`。 當內容組之間沒有聯繫時,我們可以使用 `div`
`<div>` - 一組內容 `<section>` - 幾組相關的內容 `<article>` - 幾組獨立的內容
# --instructions--
Camper Cat 打算使用 `article` 標籤來呈現他的博客頁面裏的帖子,但是他忘記在頂部的帖子上使用這個標籤。 將 `div` 標籤改爲 `article` 標籤。
# --hints--
應有三個 `article` 標籤。
```js
assert($('article').length == 3);
```
不應有 `div` 標籤。
```js
assert($('div').length == 0);
```
# --seed--
## --seed-contents--
```html
<h1>Deep Thoughts with Master Camper Cat</h1>
<main>
<div>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</div>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
</main>
```
# --solutions--
```html
<h1>Deep Thoughts with Master Camper Cat</h1>
<main>
<article>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
</main>
```

View File

@ -0,0 +1,165 @@
---
id: 587d778b367417b2b2512aa7
title: 將單選按鈕包裹在 fieldset 元素中以獲得更好的可訪問性
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJVefw'
forumTopicId: 301030
dashedName: wrap-radio-buttons-in-a-fieldset-element-for-better-accessibility
---
# --description--
接下來的表單主題是關於單選按鈕的可訪問性。 在上一個挑戰中,每個單選按鈕都有一個包含 `for` 屬性的 `label` 標籤,這些屬性值指向相關選項的 `id`。 然而單選按鈕通常成組出現,而且用戶必須選擇其中一項。
`fieldset` 標籤包裹整組單選按鈕,實現這個功能。 它經常使用 `legend` 標籤來提供分組的描述,以便屏幕閱讀器用戶會閱讀 `fieldset` 元素中的每個選項。
當選項的含義很明確時,如“性別選擇”,`fieldset``legend` 標籤可以省略。 這時,使用包含 `for` 屬性的 `label` 標籤就足夠了。
舉個例子:
```html
<form>
<fieldset>
<legend>Choose one of these three items:</legend>
<input id="one" type="radio" name="items" value="one">
<label for="one">Choice One</label><br>
<input id="two" type="radio" name="items" value="two">
<label for="two">Choice Two</label><br>
<input id="three" type="radio" name="items" value="three">
<label for="three">Choice Three</label>
</fieldset>
</form>
```
# --instructions--
當用戶使用郵件註冊時Camper Cat 想知道他們的忍者等級。 他添加了一組單選按鈕,並從我們之前的課程中吸取了教訓,爲每個選項使用帶有 `for` 屬性的 `label` 標籤。 Camper Cat 加油! 然而,他仍然需要一些幫助。 請將包含單選按鈕組的 `div` 標籤替換爲 `fieldset` 標籤;將 `p` 標籤替換爲 `legend` 標籤。
# --hints--
應存在 1 個 `fieldset` 標籤包含單選按鈕組。
```js
assert($('fieldset').length == 1);
```
確保 `fieldset` 標籤是閉合的。
```js
assert(
code.match(/<\/fieldset>/g) &&
code.match(/<\/fieldset>/g).length === code.match(/<fieldset>/g).length
);
```
應存在 1 個包含詢問用戶忍者等級內容文字的 `legend` 標籤。
```js
assert($('legend').length == 1);
```
不應存在 `div` 標籤。
```js
assert($('div').length == 0);
```
不應存在包含詢問用戶忍者等級內容文字的 `p` 標籤。
```js
assert($('p').length == 4);
```
# --seed--
## --seed-contents--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<section>
<form>
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
<label for="email">Email:</label>
<input type="text" id="email" name="email">
<!-- Only change code below this line -->
<div>
<p>What level ninja are you?</p>
<input id="newbie" type="radio" name="levels" value="newbie">
<label for="newbie">Newbie Kitten</label><br>
<input id="intermediate" type="radio" name="levels" value="intermediate">
<label for="intermediate">Developing Student</label><br>
<input id="master" type="radio" name="levels" value="master">
<label for="master">Master</label>
</div>
<!-- Only change code above this line -->
<input type="submit" name="submit" value="Submit">
</form>
</section>
<article>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
# --solutions--
```html
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<section>
<form>
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
<label for="email">Email:</label>
<input type="text" id="email" name="email">
<fieldset>
<legend>What level ninja are you?</legend>
<input id="newbie" type="radio" name="levels" value="newbie">
<label for="newbie">Newbie Kitten</label><br>
<input id="intermediate" type="radio" name="levels" value="intermediate">
<label for="intermediate">Developing Student</label><br>
<input id="master" type="radio" name="levels" value="master">
<label for="master">Master</label>
</fieldset>
<input type="submit" name="submit" value="Submit">
</form>
</section>
<article>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```

View File

@ -0,0 +1,154 @@
---
id: 587d781b367417b2b2512abe
title: 給卡片元素添加 box-shadow
challengeType: 0
videoUrl: 'https://scrimba.com/c/cvVZdUd'
forumTopicId: 301031
dashedName: add-a-box-shadow-to-a-card-like-element
---
# --description--
`box-shadow` 屬性用來給元素添加陰影,該屬性值是由逗號分隔的一個或多個陰影列表。
`box-shadow` 屬性的陰影依次由下面這些值描述:
<ul>
<li><code>offset-x</code> 陰影的水平偏移量;</li>
<li><code>offset-y</code> 陰影的垂直偏移量;</li>
<li><code>blur-radius</code> 模糊半徑;</li>
<li><code>spread-radius</code> 陰影擴展半徑;</li>
<li><code>color</code></li>
</ul>
其中 `blur-radius``spread-radius` 是可選的。
可以通過逗號分隔每個 `box-shadow` 元素的屬性來添加多個 box-shadow。
如下爲添加了模糊效果的例子,它使用了透明度較高的黑色作爲陰影:
```css
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
```
# --instructions--
元素現在有一個 `thumbnail` id。 在這個選擇器中,使用上面的示例 CSS 值在卡片上加一個 `box-shadow`
# --hints--
應該給 id 爲 `thumbnail` 的元素添加 `box-shadow` 屬性。
```js
assert(code.match(/#thumbnail\s*?{\s*?box-shadow/g));
```
`box-shadow` 屬性值應該是題目說明中指定的 CSS 值。
```js
assert(
code.match(
/box-shadow:\s*?0\s+?10px\s+?20px\s+?rgba\(\s*?0\s*?,\s*?0\s*?,\s*?0\s*?,\s*?0?\.19\)\s*?,\s*?0\s+?6px\s+?6px\s+?rgba\(\s*?0\s*?,\s*?0\s*?,\s*?0\s*?,\s*?0?\.23\)/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard" id="thumbnail">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
#thumbnail {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard" id="thumbnail">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,146 @@
---
id: 587d781b367417b2b2512abc
title: 調整文本的背景色
challengeType: 0
videoUrl: 'https://scrimba.com/c/cEDqwA6'
forumTopicId: 301032
dashedName: adjust-the-background-color-property-of-text
---
# --description--
爲了讓頁面更美觀,除了設置整個頁面的背景色以及文字顏色外,你還可以單獨設置文字的背景色,即在文字的父元素上添加 `background-color` 屬性。 在本挑戰裏我們將使用 `rgba()` 顏色,而不是之前學到的 `hex` 編碼或者 `rgb()` 顏色。
<blockquote>rgba 代表:<br>  r = red 紅色<br>  g = green 綠色<br>  b = blue 藍色<br>  a = alpha 透明度</blockquote>
RGB 值可以取在 0 到 255 之間。 alpha 值可取在 0 到 1 之間,其中 0 代表完全透明1 代表完全不透明。 `rgba()` 在需要設置顏色透明度時十分有用, 這意味着你可以做出一些很漂亮的半透明效果。
在本挑戰裏你將會用到這個代碼 `background-color: rgba(45, 45, 45, 0.1)`。 它表示背景是黑灰色,因爲設置了透明度爲 0.1,所以幾乎是透明的。
# --instructions--
爲了讓文字更醒目,設置 `h4` 元素的 `background-color` 屬性值爲上面指定的 `rgba()`
同時移除 `h4``height` 屬性,並添加 `padding` 屬性,值爲 10px。
# --hints--
你應該給 `h4` 元素添加一個 `background-color` 屬性並且賦值 `rgba(45, 45, 45, 0.1)`
```js
assert(
/(background-color|background):rgba\(45,45,45,0?\.1\)(;?}|;)/gi.test(
code.replace(/\s/g, '')
)
);
```
`h4` 元素的 `padding` 屬性值應爲 10px。
```js
assert(
$('h4').css('padding-top') == '10px' &&
$('h4').css('padding-right') == '10px' &&
$('h4').css('padding-bottom') == '10px' &&
$('h4').css('padding-left') == '10px'
);
```
`h4` 元素不應有 `height` 屬性。
```js
assert(!($('h4').css('height') == '25px'));
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
padding: 10px;
background-color: rgba(45, 45, 45, 0.1);
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,130 @@
---
id: 587d78a4367417b2b2512ad3
title: 將各種元素的顏色調整爲互補色
challengeType: 0
videoUrl: 'https://scrimba.com/c/cWmPpud'
forumTopicId: 301033
dashedName: adjust-the-color-of-various-elements-to-complementary-colors
---
# --description--
通過前面關卡的學習,我們知道了補色搭配能形成強列的對比效果,讓內容更富生機。 但是如果使用不當效果會適得其反:比如將文字背景色和文字顏色設置爲互補色,這樣文字會很難看清。 通常的做法是,一種顏色做爲主要顏色,然後使用其補色用來裝點那些需要用戶特別注意的部分。
# --instructions--
使用深青色(`#09A7A1`)做爲頁面主色,用其補色橙色(`#FF790E`)來裝飾登錄按鈕。 把 `header``footer``background-color` 從黑色改成深青色。 然後把 `h2` 的文字 `color` 也改成深青色。 最後,把 `button``background-color` 改成橙色。
# --hints--
`header` 元素的 `background-color` 屬性值應爲 #09A7A1
```js
assert($('header').css('background-color') == 'rgb(9, 167, 161)');
```
`footer` 元素的 `background-color` 屬性值應爲 #09A7A1
```js
assert($('footer').css('background-color') == 'rgb(9, 167, 161)');
```
`h2` 元素的 `color` 屬性值應爲 #09A7A1
```js
assert($('h2').css('color') == 'rgb(9, 167, 161)');
```
`button` 元素的 `background-color` 屬性值應爲 #FF790E
```js
assert($('button').css('background-color') == 'rgb(255, 121, 14)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: white;
}
header {
background-color: black;
color: white;
padding: 0.25em;
}
h2 {
color: black;
}
button {
background-color: white;
}
footer {
background-color: black;
color: white;
padding: 0.5em;
}
</style>
<header>
<h1>Cooking with FCC!</h1>
</header>
<main>
<article>
<h2>Machine Learning in the Kitchen</h2>
<p>Join this two day workshop that walks through how to implement cutting-edge snack-getting algorithms with a command line interface. Coding usually involves writing exact instructions, but sometimes you need your computer to execute flexible commands, like <code>fetch Pringles</code>.</p>
<button>Sign Up</button>
</article>
<article>
<h2>Bisection Vegetable Chopping</h2>
<p>This week-long retreat will level-up your coding ninja skills to actual ninja skills. No longer is the humble bisection search limited to sorted arrays or coding interview questions, applying its concepts in the kitchen will have you chopping carrots in O(log n) time before you know it.</p>
<button>Sign Up</button>
</article>
</main>
<br>
<footer>&copy; 2018 FCC Kitchen</footer>
```
# --solutions--
```html
<style>
body {
background-color: white;
}
header {
background-color: #09A7A1;
color: white;
padding: 0.25em;
}
h2 {
color: #09A7A1;
}
button {
background-color: #FF790E;
}
footer {
background-color: #09A7A1;
color: white;
padding: 0.5em;
}
</style>
<header>
<h1>Cooking with FCC!</h1>
</header>
<main>
<article>
<h2>Machine Learning in the Kitchen</h2>
<p>Join this two day workshop that walks through how to implement cutting-edge snack-getting algorithms with a command line interface. Coding usually involves writing exact instructions, but sometimes you need your computer to execute flexible commands, like <code>fetch Pringles</code>.</p>
<button>Sign Up</button>
</article>
<article>
<h2>Bisection Vegetable Chopping</h2>
<p>This week-long retreat will level-up your coding ninja skills to actual ninja skills. No longer is the humble bisection search limited to sorted arrays or coding interview questions, applying its concepts in the kitchen will have you chopping carrots in O(log n) time before you know it.</p>
<button>Sign Up</button>
</article>
</main>
<br>
<footer>&copy; 2018 FCC Kitchen</footer>
```

View File

@ -0,0 +1,118 @@
---
id: 587d7791367417b2b2512ab5
title: 使用 height 屬性調整元素的寬度
challengeType: 0
videoUrl: 'https://scrimba.com/c/cEDaDTN'
forumTopicId: 301034
dashedName: adjust-the-height-of-an-element-using-the-height-property
---
# --description--
`width` 屬性類似,你可以使用 CSS 裏面的 `height` 屬性來指定元素的高度。 下面這段代碼可以把圖片的高度設置爲 20px
```css
img {
height: 20px;
}
```
# --instructions--
`h4` 標籤添加 `height` 屬性並將屬性值設置爲 25px。
**注意:**可能需要將瀏覽器的縮放比調整爲 100% 才能通過這一挑戰。
# --hints--
`h4``height` 屬性值應爲 25px。
```js
assert(
Math.round(document.querySelector('h4').getBoundingClientRect().height) ===
25 &&
/h4{\S*height:25px(;\S*}|})/.test($('style').text().replace(/\s/g, ''))
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
}
p {
text-align: justify;
}
.links {
margin-right: 20px;
text-align: left;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
margin-right: 20px;
text-align: left;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,72 @@
---
id: 587d781d367417b2b2512ac8
title: 調整錨點的懸停狀態
challengeType: 0
videoUrl: 'https://scrimba.com/c/cakRGcm'
forumTopicId: 301035
dashedName: adjust-the-hover-state-of-an-anchor-tag
---
# --description--
本挑戰將要涉及到僞類。 僞類是可以添加到選擇器上的關鍵字,用來選擇特定狀態的元素。
比如,可以使用 `:hover` 僞類選擇器來選取超鏈接的懸停狀態。 下面的代碼可以在鼠標懸停在超鏈接上時將其 `color` 變成紅色:
```css
a:hover {
color: red;
}
```
# --instructions--
代碼編輯器裏面已經有了一個 CSS 規則把所有的 `a` 標籤定義成了黑色。 請添加一個規則,使得用戶懸停在 `a` 標籤時,標籤的 `color` 變成藍色。
# --hints--
超鏈接的 `color` 應該保持黑色,應只添加 `:hover` CSS 規則。
```js
assert($('a').css('color') == 'rgb(0, 0, 0)');
```
懸停超鏈接時超鏈接的 `color` 應該變成藍色。
```js
assert(
code.match(
/a:hover\s*?{\s*?color:\s*?(blue|rgba\(\s*?0\s*?,\s*?0\s*?,\s*?255\s*?,\s*?1\s*?\)|#00F|rgb\(\s*?0\s*?,\s*?0\s*?,\s*?255\s*?\))\s*?;\s*?}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
a {
color: #000;
}
</style>
<a href="https://freecatphotoapp.com/" target="_blank">CatPhotoApp</a>
```
# --solutions--
```html
<style>
a {
color: #000;
}
a:hover {
color: rgba(0,0,255,1);
}
</style>
<a href="https://freecatphotoapp.com/" target="_blank">CatPhotoApp</a>
```

View File

@ -0,0 +1,129 @@
---
id: 587d78a4367417b2b2512ad4
title: 調整顏色的色相
challengeType: 0
videoUrl: 'https://scrimba.com/c/cPp38TZ'
forumTopicId: 301036
dashedName: adjust-the-hue-of-a-color
---
# --description--
顏色具有多種特性,包括色相、飽和度和亮度。 CSS3 引入了 `hsl()` 做爲顏色的描述方式。
**色相**是色彩的基本屬性,就是平常所說的顏色名稱,如紅色、黃色等。 以顏色光譜爲例,光譜左邊從紅色開始,移動到中間的綠色,一直到右邊的藍色,色相值就是沿着這條線的取值。 在 `hsl()` 裏面,色相用色環來代替光譜,色相值就是色環裏面的顏色對應的從 0 到 360 度的角度值。
**飽和度**是指色彩的純度,也就是顏色裏灰色的佔比。 飽和度越高則灰色佔比越少,色彩也就越純;反之則完全是灰色。 飽和度的取值範圍是表示灰色所佔百分比的 0 至 100。
**亮度**決定顏色的明暗程度,也就是顏色裏白色或者黑色的佔比。 其中100% 的亮度表示純白色, 0% 的亮度則表示純黑色;而 50% 的亮度就表示在色相中選取的顏色。
下面是一些使用 `hsl()` 描述顏色的例子,顏色都爲滿飽和度,中等亮度:
<table class='table table-striped'><thead><tr><th>顏色</th><th>HSL</th></tr></thead><tbody><tr><td></td><td>hsl(0, 100%, 50%)</td></tr><tr><td></td><td>hsl(60, 100%, 50%)</td></tr><tr><td></td><td>hsl(120, 100%, 50%)</td></tr><tr><td>藍綠</td><td>hsl(180, 100%, 50%)</td></tr><tr><td></td><td>hsl(240, 100%, 50%)</td></tr><tr><td>品紅</td><td>hsl(300, 100%, 50%)</td></tr></tbody></table>
# --instructions--
將 class 爲 `green``cyan``blue``div``background-color` 屬性值設置爲使用 `hsl()` 表示的顏色。 顏色都爲滿飽和度,亮度中等。
# --hints--
應使用 `hsl()` 屬性來設置顏色爲 `green`
```js
assert(code.match(/\.green\s*?{\s*?background-color:\s*?hsl/gi));
```
應使用 `hsl()` 屬性來設置顏色爲 `cyan`
```js
assert(code.match(/\.cyan\s*?{\s*?background-color:\s*?hsl/gi));
```
應使用 `hsl()` 屬性來設置顏色爲 `blue`
```js
assert(code.match(/\.blue\s*?{\s*?background-color:\s*?hsl/gi));
```
class 爲 `green``div` 元素的 `background-color` 屬性值應爲綠色。
```js
assert($('.green').css('background-color') == 'rgb(0, 255, 0)');
```
class 爲 `cyan``div` 元素的 `background-color` 屬性值應爲藍綠色。
```js
assert($('.cyan').css('background-color') == 'rgb(0, 255, 255)');
```
class 爲 `blue``div` 元素的 `background-color` 屬性值應爲藍色。
```js
assert($('.blue').css('background-color') == 'rgb(0, 0, 255)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: #FFFFFF;
}
.green {
background-color: #000000;
}
.cyan {
background-color: #000000;
}
.blue {
background-color: #000000;
}
div {
display: inline-block;
height: 100px;
width: 100px;
}
</style>
<div class="green"></div>
<div class="cyan"></div>
<div class="blue"></div>
```
# --solutions--
```html
<style>
body {
background-color: #FFFFFF;
}
.green {
background-color: hsl(120, 100%, 50%);
}
.cyan {
background-color: hsl(180, 100%, 50%);
}
.blue {
background-color: hsl(240, 100%, 50%);
}
div {
display: inline-block;
height: 100px;
width: 100px;
}
</style>
<div class="green"></div>
<div class="cyan"></div>
<div class="blue"></div>
```

View File

@ -0,0 +1,118 @@
---
id: 587d781b367417b2b2512abd
title: 調整標題與段落的大小
challengeType: 0
videoUrl: 'https://scrimba.com/c/c3bRPTz'
forumTopicId: 301037
dashedName: adjust-the-size-of-a-header-versus-a-paragraph-tag
---
# --description--
標題標籤的字體大小(從 `h1``h6`)一般應該大於段落標籤的字體大小。 這使用戶更容易在視覺上了解頁面上所有內容的佈局和重要程度。 你可以使用 `font-size` 屬性來設置元素內文字的大小。
# --instructions--
`h4` 標籤的 `font-size` 的屬性值改成 27px讓標題更醒目。
# --hints--
應給 `h4` 元素添加一個 `font-size` 屬性並將屬性值設置爲 27px。
```js
assert($('h4').css('font-size') == '27px');
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,119 @@
---
id: 587d78a4367417b2b2512ad5
title: 調整顏色的色調
challengeType: 0
videoUrl: 'https://scrimba.com/c/cEDJvT7'
forumTopicId: 301038
dashedName: adjust-the-tone-of-a-color
---
# --description--
`hsl()` 使 CSS 更改顏色色調更加方便。 比如,給一個純色添加白色可以調出更淺的色調;添加黑色可以創造更深的色調。 另外,還可以通過給純色添加灰色來同時改變顏色的深淺和明暗。 回憶下 `hsl()` 裏面的 sl 分辨代表飽和度和亮度。 飽和度代表灰色的佔比,亮度代表白色和黑色的佔比。 這在你想獲取一個基準色的變種的情景下會十分有用。
# --instructions--
所有元素的默認 `background-color` 都是 `transparent`。 當前頁面的導航欄 `nav` 背景色之所以看起來是藍綠色,是因爲它背後的 `header``background-color` 屬性值爲 `cyan`。 給 `nav` 元素增加一個 `background-color`,使它的顏色也爲 `cyan`,飽和度爲 `80%`,亮度爲 `25%`,以修改它的色調和陰影。
# --hints--
`nav` 元素應該有一個使用 `hsl()` 屬性調節藍綠色調的 `background-color` 屬性。
```js
assert(
code.match(/nav\s*?{\s*?background-color:\s*?hsl\(180,\s*?80%,\s*?25%\)/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
header {
background-color: hsl(180, 90%, 35%);
color: #FFFFFF;
}
nav {
}
h1 {
text-indent: 10px;
padding-top: 10px;
}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;
}
nav li {
display: inline;
margin-right: 20px;
}
a {
text-decoration: none;
color: inherit;
}
</style>
<header>
<h1>Cooking with FCC!</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
```
# --solutions--
```html
<style>
header {
background-color: hsl(180, 90%, 35%);
color: #FFFFFF;
}
nav {
background-color: hsl(180, 80%, 25%);
}
h1 {
text-indent: 10px;
padding-top: 10px;
}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;
}
nav li {
display: inline;
margin-right: 20px;
}
a {
text-decoration: none;
color: inherit;
}
</style>
<header>
<h1>Cooking with FCC!</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
```

View File

@ -0,0 +1,115 @@
---
id: 587d7791367417b2b2512ab4
title: 使用 width 屬性調整元素的寬度
challengeType: 0
videoUrl: 'https://scrimba.com/c/cvVLPtN'
forumTopicId: 301039
dashedName: adjust-the-width-of-an-element-using-the-width-property
---
# --description--
你可以使用 CSS 裏的 `width` 屬性來指定元素的寬度。 屬性值可以是相對單位(比如 `em`),絕對單位(比如 `px`),或者包含塊(父元素)寬度的百分比。 下面這段代碼可以把圖片的寬度設置爲 220px
```css
img {
width: 220px;
}
```
# --instructions--
爲卡片元素添加 `width` 屬性,並將它的寬度設置爲 245px。 使用 `fullCard` class 來選擇卡片元素。
# --hints--
應使用 `fullCard` class 選擇器將卡片的 `width` 屬性值設置爲 `245px`
```js
const fullCard = code.match(/\.fullCard\s*{[\s\S]+?[^}]}/g);
assert(
fullCard &&
/width\s*:\s*245px\s*(;|})/gi.test(fullCard[0]) &&
$('.fullCard').css('maxWidth') === 'none'
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
}
p {
text-align: justify;
}
.links {
margin-right: 20px;
text-align: left;
}
.fullCard {
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
}
p {
text-align: justify;
}
.links {
margin-right: 20px;
text-align: left;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,141 @@
---
id: 587d78a8367417b2b2512ae5
title: 以可變速率來給元素添加動畫
challengeType: 0
videoUrl: 'https://scrimba.com/c/cZ89WA4'
forumTopicId: 301040
dashedName: animate-elements-at-variable-rates
---
# --description--
改變相似元素的動畫頻率的方法有很多。 目前我們接觸到的就有 `animation-iteration-count``@keyframes`
舉例說明,右邊的動畫包含了兩個小星星,每個小星星都在 `@keyframes` 爲 20% 處變小並且透明度變低,也就是一閃一閃的動畫效果。 你可以通過改變其中一個元素的 `@keyframes` 規則以使兩個小星星以不同的頻率閃爍。
# --instructions--
請將 class 爲 `star-1` 的元素的 `@keyframes` 爲設置爲 50%,以此改變其動畫頻率。
# --hints--
class 爲 `star-1` 的元素的 `@keyframes` 規則應爲 50%。
```js
assert(code.match(/twinkle-1\s*?{\s*?50%/g));
```
# --seed--
## --seed-contents--
```html
<style>
.stars {
background-color: white;
height: 30px;
width: 30px;
border-radius: 50%;
animation-iteration-count: infinite;
}
.star-1 {
margin-top: 15%;
margin-left: 60%;
animation-name: twinkle-1;
animation-duration: 1s;
}
.star-2 {
margin-top: 25%;
margin-left: 25%;
animation-name: twinkle-2;
animation-duration: 1s;
}
@keyframes twinkle-1 {
20% {
transform: scale(0.5);
opacity: 0.5;
}
}
@keyframes twinkle-2 {
20% {
transform: scale(0.5);
opacity: 0.5;
}
}
#back {
position: fixed;
padding: 0;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(black, #000099, #66c2ff, #ffcccc, #ffeee6);
}
</style>
<div id="back"></div>
<div class="star-1 stars"></div>
<div class="star-2 stars"></div>
```
# --solutions--
```html
<style>
.stars {
background-color: white;
height: 30px;
width: 30px;
border-radius: 50%;
animation-iteration-count: infinite;
}
.star-1 {
margin-top: 15%;
margin-left: 60%;
animation-name: twinkle-1;
animation-duration: 1s;
}
.star-2 {
margin-top: 25%;
margin-left: 25%;
animation-name: twinkle-2;
animation-duration: 1s;
}
@keyframes twinkle-1 {
50% {
transform: scale(0.5);
opacity: 0.5;
}
}
@keyframes twinkle-2 {
20% {
transform: scale(0.5);
opacity: 0.5;
}
}
#back {
position: fixed;
padding: 0;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(black, #000099, #66c2ff, #ffcccc, #ffeee6);
}
</style>
<div id="back"></div>
<div class="star-1 stars"></div>
<div class="star-2 stars"></div>
```

View File

@ -0,0 +1,107 @@
---
id: 587d78a8367417b2b2512ae3
title: 使用無限的動畫計數製作永不停止的動畫
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJDVfq'
forumTopicId: 301041
dashedName: animate-elements-continually-using-an-infinite-animation-count
---
# --description--
之前的關卡里介紹了一些動畫屬性以及 `@keyframes` 規則的用法。 還有一個常用的動畫屬性是 `animation-iteration-count`,這個屬性允許你控制動畫循環的次數。 下面是一個例子:
```css
animation-iteration-count: 3;
```
在這裏動畫會在運行 3 次後停止,如果想讓動畫一直運行,可以把值設置成 `infinite`
# --instructions--
`animation-iteration-count` 屬性改成 `infinite`,使右邊的球一直跳躍。
# --hints--
`animation-iteration-count` 屬性的值應爲 `infinite`
```js
assert($('#ball').css('animation-iteration-count') == 'infinite');
```
# --seed--
## --seed-contents--
```html
<style>
#ball {
width: 100px;
height: 100px;
margin: 50px auto;
position: relative;
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
animation-name: bounce;
animation-duration: 1s;
animation-iteration-count: 3;
}
@keyframes bounce{
0% {
top: 0px;
}
50% {
top: 249px;
width: 130px;
height: 70px;
}
100% {
top: 0px;
}
}
</style>
<div id="ball"></div>
```
# --solutions--
```html
<style>
#ball {
width: 100px;
height: 100px;
margin: 50px auto;
position: relative;
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
animation-name: bounce;
animation-duration: 1s;
animation-iteration-count: infinite;
}
@keyframes bounce{
0% {
top: 0px;
}
50% {
top: 249px;
width: 130px;
height: 70px;
}
100% {
top: 0px;
}
}
</style>
<div id="ball"></div>
```

View File

@ -0,0 +1,155 @@
---
id: 587d78a8367417b2b2512ae6
title: 以可變速率來給多個元素添加動畫
challengeType: 0
videoUrl: 'https://scrimba.com/c/cnpWZc9'
forumTopicId: 301042
dashedName: animate-multiple-elements-at-variable-rates
---
# --description--
在前面的關卡里,我們通過修改 `@keyframes` 改變了兩個相似動畫元素的頻率。 你也可以通過改變多個元素的 `animation-duration` 來達到同樣的效果。
在代碼編輯器裏運行的動畫中,天空中有三顆以同樣頻率不停閃爍的星星。 你可以設置每一個星星的 `animation-duration` 屬性爲不同的值,以使其具有不同的閃爍頻率。
# --instructions--
依次設置 class 爲 `star-1``star-2``star-3` 的元素的 `animation-duration` 爲 1s、0.9s、1.1s。
# --hints--
class 爲 `star-1``animation-duration` 屬性值應該 1s。
```js
assert($('.star-1').css('animation-duration') == '1s');
```
class 爲 `star-2``animation-duration` 屬性值應該 0.9s。
```js
assert($('.star-2').css('animation-duration') == '0.9s');
```
class 爲 `star-3``animation-duration` 屬性值應該 1.1s。
```js
assert($('.star-3').css('animation-duration') == '1.1s');
```
# --seed--
## --seed-contents--
```html
<style>
.stars {
background-color: white;
height: 30px;
width: 30px;
border-radius: 50%;
animation-iteration-count: infinite;
}
.star-1 {
margin-top: 15%;
margin-left: 60%;
animation-duration: 1s;
animation-name: twinkle;
}
.star-2 {
margin-top: 25%;
margin-left: 25%;
animation-duration: 1s;
animation-name: twinkle;
}
.star-3 {
margin-top: 10%;
margin-left: 50%;
animation-duration: 1s;
animation-name: twinkle;
}
@keyframes twinkle {
20% {
transform: scale(0.5);
opacity: 0.5;
}
}
#back {
position: fixed;
padding: 0;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(black, #000099, #66c2ff, #ffcccc, #ffeee6);
}
</style>
<div id="back"></div>
<div class="star-1 stars"></div>
<div class="star-2 stars"></div>
<div class="star-3 stars"></div>
```
# --solutions--
```html
<style>
.stars {
background-color: white;
height: 30px;
width: 30px;
border-radius: 50%;
animation-iteration-count: infinite;
}
.star-1 {
margin-top: 15%;
margin-left: 60%;
animation-duration: 1s;
animation-name: twinkle;
}
.star-2 {
margin-top: 25%;
margin-left: 25%;
animation-duration: 0.9s;
animation-name: twinkle;
}
.star-3 {
margin-top: 10%;
margin-left: 50%;
animation-duration: 1.1s;
animation-name: twinkle;
}
@keyframes twinkle {
20% {
transform: scale(0.5);
opacity: 0.5;
}
}
#back {
position: fixed;
padding: 0;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(black, #000099, #66c2ff, #ffcccc, #ffeee6);
}
</style>
<div id="back"></div>
<div class="star-1 stars"></div>
<div class="star-2 stars"></div>
<div class="star-3 stars"></div>
```

View File

@ -0,0 +1,56 @@
---
id: 587d78a3367417b2b2512ad0
title: 使用 margin 屬性將元素水平居中
challengeType: 0
videoUrl: 'https://scrimba.com/c/cyLJqU4'
forumTopicId: 301043
dashedName: center-an-element-horizontally-using-the-margin-property
---
# --description--
在應用設計中經常需要把一個塊級元素水平居中顯示。 一種常見的實現方式是把塊級元素的 `margin` 值設置爲 auto。
同樣的,這個方法也對圖片奏效。 圖片默認是內聯元素,但是可以通過設置其 `display` 屬性爲 `block`來把它變成塊級元素。
# --instructions--
通過添加一個值爲 `auto``margin` 屬性,將 `div` 在頁面居中。
# --hints--
`div` 應有一個 `margin`,設置爲 `auto`
```js
assert(code.match(/margin:\s*?auto;/g));
```
# --seed--
## --seed-contents--
```html
<style>
div {
background-color: blue;
height: 100px;
width: 100px;
}
</style>
<div></div>
```
# --solutions--
```html
<style>
div {
background-color: blue;
height: 100px;
width: 100px;
margin: auto;
}
</style>
<div></div>
```

View File

@ -0,0 +1,77 @@
---
id: 587d781e367417b2b2512ac9
title: 更改元素的相對位置
challengeType: 0
videoUrl: 'https://scrimba.com/c/czVmMtZ'
forumTopicId: 301044
dashedName: change-an-elements-relative-position
---
# --description--
在 CSS 裏一切 HTML 元素皆爲盒子,也就是通常所說的<dfn>盒模型</dfn>。 塊級元素自動從新的一行開始(比如標題、段落以及 div行內元素排列在上一個元素後比如圖片以及 span。 元素默認按照這種方式佈局稱爲文檔的<dfn>普通流</dfn>,同時 CSS 提供了 position 屬性來覆蓋它。
當元素的定位設置爲 `relative` 時,它允許你通過 CSS 指定該元素在當前文檔流頁面下的*相對*偏移量。 CSS 裏控制各個方向偏移量的屬性是 `left``right``top``bottom`。 它們代表從原來位置向遠離該方向*偏移*指定的像素、百分比或者 em。 下面的例子展示了段落向上偏移 10px
```css
p {
position: relative;
bottom: 10px;
}
```
把元素的位置設置成相對,並不會改變該元素在佈局中所佔的位置,也不會對其它元素的位置產生影響。
**注意:**定位可以使頁面佈局更靈活、高效。 不管元素的定位是怎樣的HTML 標記在從上到下閱讀起來時應該是整潔的、有意義的。 這樣可以讓視障人士(重度依賴輔助設備比如屏幕閱讀軟件的人們)也能夠無障礙地瀏覽你的網頁。
# --instructions--
`h2``position` 設置成 `relative`,使用相應的 CSS 屬性調整它的位置,使其相對 `top` 偏移 15px同時還在文檔流中處於原來的位置。 這不會對 h1 和 p 元素的位置產生影響。
# --hints--
`h2` 元素應有一個值爲 `relative``position` 屬性。
```js
assert($('h2').css('position') == 'relative');
```
你應該使用 CSS 屬性調整 `h2` 的位置,使其從原來的位置相對 `top` 偏移 15px。
```js
assert($('h2').css('top') == '15px');
```
# --seed--
## --seed-contents--
```html
<style>
h2 {
}
</style>
<body>
<h1>On Being Well-Positioned</h1>
<h2>Move me!</h2>
<p>I still think the h2 is where it normally sits.</p>
</body>
```
# --solutions--
```html
<style>
h2 {
position: relative;
top: 15px;
}
</style>
<body>
<h1>On Being Well-Positioned</h1>
<h2>Move me!</h2>
<p>I still think the h2 is where it normally sits.</p>
</body>
```

View File

@ -0,0 +1,127 @@
---
id: 587d78a8367417b2b2512ae7
title: 使用關鍵字更改動畫定時器
challengeType: 0
videoUrl: 'https://scrimba.com/c/cJKvwCM'
forumTopicId: 301045
dashedName: change-animation-timing-with-keywords
---
# --description--
在 CSS 動畫裏,`animation-timing-function` 用來定義動畫的速度曲線。 速度曲線決定了動畫從一套 CSS 樣式變爲另一套所用的時間。 如果要描述的動畫是一輛車在指定時間內(`animation-duration`)從 A 運動到 B那麼 `animation-timing-function` 表述的就是車在運動中的加速和減速等過程。
有一些預定義的關鍵字可用於常見的選項。 比如,默認值是 `ease`,動畫以低速開始,然後加快,在結束前變慢。 其它常用的值包括 `ease-out`:動畫以高速開始,以低速結束;`ease-in`,動畫以低速開始,以高速結束;`linear`:動畫從頭到尾的速度是相同的。
# --instructions--
給 id 爲 `ball1``ball2` 的元素添加 `animation-timing-function``ball1` 的屬性值爲 `linear``ball2` 的屬性值爲 `ease-out`。 它們的 `animation-duration` 都爲 2 秒,注意觀察它們在開始和結束時的不同。
# --hints--
id 爲 `ball1` 的元素的 `animation-timing-function` 屬性值應爲 `linear`
```js
const ball1Animation = __helpers.removeWhiteSpace(
$('#ball1').css('animation-timing-function')
);
assert(ball1Animation == 'linear' || ball1Animation == 'cubic-bezier(0,0,1,1)');
```
id 爲 `ball2` 的元素的 `animation-timing-function` 屬性值爲 `ease-out`
```js
const ball2Animation = __helpers.removeWhiteSpace(
$('#ball2').css('animation-timing-function')
);
assert(
ball2Animation == 'ease-out' || ball2Animation == 'cubic-bezier(0,0,0.58,1)'
);
```
# --seed--
## --seed-contents--
```html
<style>
.balls {
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#ball1 {
left:27%;
}
#ball2 {
left:56%;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id="ball1"></div>
<div class="balls" id="ball2"></div>
```
# --solutions--
```html
<style>
.balls {
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#ball1 {
left:27%;
animation-timing-function: linear;
}
#ball2 {
left:56%;
animation-timing-function: ease-out;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id="ball1"></div>
<div class="balls" id="ball2"></div>
```

View File

@ -0,0 +1,81 @@
---
id: 587d78a3367417b2b2512acf
title: 使用 z-index 屬性更改重疊元素的位置
challengeType: 0
videoUrl: 'https://scrimba.com/c/cM94aHk'
forumTopicId: 301046
dashedName: change-the-position-of-overlapping-elements-with-the-z-index-property
---
# --description--
當一些元素在位置上重疊時(例如,使用 `position: absolute | relative | fixed | sticky` 時),在 HTML 裏後出現的元素會默認顯示在更早出現的元素的上面。 你可以使用 `z-index` 屬性指定元素的堆疊次序。 `z-index` 的取值是整數,數值大的元素會疊放到數值小的元素上面。
# --instructions--
給 class 爲 `first` 的元素(紅色的方塊)添加 `z-index` 屬性並將屬性值設置爲 2使它顯示在藍色方塊的上方。
# --hints--
class 爲 `first` 的元素的 `z-index` 屬性值應爲 2。
```js
assert($('.first').css('z-index') == '2');
```
# --seed--
## --seed-contents--
```html
<style>
div {
width: 60%;
height: 200px;
margin-top: 20px;
}
.first {
background-color: red;
position: absolute;
}
.second {
background-color: blue;
position: absolute;
left: 40px;
top: 50px;
z-index: 1;
}
</style>
<div class="first"></div>
<div class="second"></div>
```
# --solutions--
```html
<style>
div {
width: 60%;
height: 200px;
margin-top: 20px;
}
.first {
background-color: red;
position: absolute;
z-index: 2;
}
.second {
background-color: blue;
position: absolute;
left: 40px;
top: 50px;
z-index: 1;
}
</style>
<div class="first"></div>
<div class="second"></div>
```

View File

@ -0,0 +1,76 @@
---
id: 587d78a5367417b2b2512ad6
title: 創建一個 CSS 線性漸變
challengeType: 0
videoUrl: 'https://scrimba.com/c/cg4dpt9'
forumTopicId: 301047
dashedName: create-a-gradual-css-linear-gradient
---
# --description--
HTML 元素的背景色並不侷限於單色。 CSS 還爲我們提供了顏色漸變。 可通過 `background` 裏的 `linear-gradient()` 實現線性漸變, 以下是它的語法:
```css
background: linear-gradient(gradient_direction, color 1, color 2, color 3, ...);
```
第一個參數指定了顏色過渡的方向——它的值是角度,`90deg` 表示垂直漸變(從左到右),`45deg` 表示沿對角線漸變(從左下方到右上方)。 其他參數指定了漸變顏色的順序:
例如:
```css
background: linear-gradient(90deg, red, yellow, rgb(204, 204, 255));
```
# --instructions--
使用 `linear-gradient()``div` 元素添加 `background` 漸變色,漸變角度爲 35 度,從 `#CCFFFF` 過渡到 `#FFCCCC`
# --hints--
`div` 元素應有一個指定方向和顏色的 `linear-gradient` `background`
```js
assert(
$('div')
.css('background-image')
.match(
/linear-gradient\(35deg, rgb\(204, 255, 255\), rgb\(255, 204, 204\)\)/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
div {
border-radius: 20px;
width: 70%;
height: 400px;
margin: 50px auto;
}
</style>
<div></div>
```
# --solutions--
```html
<style>
div {
border-radius: 20px;
width: 70%;
height: 400px;
margin: 50px auto;
background: linear-gradient(35deg, #CCFFFF, #FFCCCC);
}
</style>
<div></div>
```

View File

@ -0,0 +1,89 @@
---
id: 587d78a6367417b2b2512add
title: 使用 CSS 創建一個圖形
challengeType: 0
videoUrl: 'https://scrimba.com/c/cEDWPs6'
forumTopicId: 301048
dashedName: create-a-graphic-using-css
---
# --description--
通過使用不同的選擇器和屬性,你可以做出有趣的形狀, 一個簡單的例子是新月形狀。 在這個挑戰中,我們會學習如何使用 `box-shadow` 屬性來設置元素的陰影,以及使用 `border-radius` 屬性控制元素的圓角邊框。
首先我們來創建一個圓的、透明的圖形,它具有模糊陰影並略微向兩邊遞減。 如你所見,這個陰影其實就是新月形狀。
爲了創建一個圓形的對象,`border-radius` 應該被設置成 50%。
你應該還記得之前關卡的 `box-shadow` 屬性以及它的依次取值 `offset-x``offset-y``blur-radius``spread-radius` 和顏色值。 其中 `blur-radius``spread-radius` 是可選的。
# --instructions--
把編輯器裏的正方形元素變成新月形狀。 首先,把 `background-color` 改爲 `transparent`,接着把 `border-radius` 屬性設置成 50%,以創建一個圓形。 最後,更改 `box-shadow` 屬性,使其 `offset-x` 爲 25px`offset-y` 爲 10px`blur-radius` 爲 0`spread-radius` 爲 0顏色爲 `blue`
# --hints--
`background-color` 屬性值應爲 `transparent`
```js
assert(code.match(/background-color:\s*?transparent;/gi));
```
`border-radius` 屬性的值應該設置爲 `50%`
```js
assert(code.match(/border-radius:\s*?50%;/gi));
```
更改 `box-shadow` 屬性,使其 `offset-x` 爲 25px`offset-y` 爲 10px`blur-radius` 爲 0`spread-radius` 爲 0顏色爲 `blue`
```js
assert(
code.match(/box-shadow:\s*?25px\s+?10px\s+?0(px)?\s+?0(px)?\s+?blue\s*?;/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
.center {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100px;
height: 100px;
background-color: blue;
border-radius: 0px;
box-shadow: 25px 10px 10px 10px green;
}
</style>
<div class="center"></div>
```
# --solutions--
```html
<style>
.center {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100px;
height: 100px;
background-color: transparent;
border-radius: 50%;
box-shadow: 25px 10px 0 0 blue;
}
</style>
<div class="center"></div>
```

View File

@ -0,0 +1,122 @@
---
id: 587d781b367417b2b2512abb
title: 使用 hr 標籤創建水平線
challengeType: 0
videoUrl: 'https://scrimba.com/c/c3bR8t7'
forumTopicId: 301049
dashedName: create-a-horizontal-line-using-the-hr-element
---
# --description--
你可以用 `hr` 標籤來創建一條寬度撐滿父元素的水平線。 這種水平分割線一般用來表示內容主題的改變,或在視覺上將文檔分隔成幾個部分。
# --instructions--
在卡片標題元素 `h4` 下方添加一個 `hr` 標籤。
**注意:**HTML 中的 `hr` 是自閉合標籤,所以我們不需要爲它添加結束標籤。
# --hints--
應存在一個 `hr` 標籤。
```js
assert($('hr').length == 1);
```
`hr` 應在標題和段落之間。
```js
assert(code.match(/<\/h4>\s*?<hr(>|\s*?\/>)\s*?<p>/gi));
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4><s>Google</s>Alphabet</h4>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4><s>Google</s>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,146 @@
---
id: 587d78a6367417b2b2512ade
title: 使用 CSS 和 HTML 創建更復雜的形狀
challengeType: 0
videoUrl: 'https://scrimba.com/c/cPpz4fr'
forumTopicId: 301050
dashedName: create-a-more-complex-shape-using-css-and-html
---
# --description--
世界上最流行的形狀非心形莫屬了,在本挑戰中我們將用純 CSS 創建一個心形。 但是首先你需要了解僞元素 `::before``::after`。 僞元素可以在所選元素之前或之後添加一些內容。 在下面的代碼中,`::before` 僞元素用來給 class 爲 `heart` 的元素添加一個正方形:
```css
.heart::before {
content: "";
background-color: yellow;
border-radius: 25%;
position: absolute;
height: 50px;
width: 70px;
top: -50px;
left: 5px;
}
```
`::before``::after` 必須配合 `content` 來使用。 這個屬性通常用來給元素添加內容諸如圖片或者文字。 儘管有時 `::before``::after` 是用來實現形狀而非文字,但 `content` 屬性仍然是必需的,此時它的值可以是空字符串。 在上面的例子裏class 爲 `heart` 元素的 `::before` 僞類添加了一個黃色的長方形,長方形的高和寬分別爲 `50px``70px`。 這個矩形有圓角,因爲它的 `border-radius` 爲 25%,它的位置是絕對位置,位於離元素左邊和頂部分別是 `5px``50px` 的位置。
# --instructions--
把屏幕裏的元素變成心形。 在 `heart::after` 選擇器裏,把 `background-color` 改成 `pink`,把 `border-radius` 改成 50%。
接下來,用類選擇器選取 class 爲 `heart`(只是 `heart`)的元素,爲它添加 `transform` 屬性。 使用 `rotate()` 函數並設置角度爲 -45 度。
最後,在 `heart::before` 選擇器裏面,設置 `content` 屬性值爲空字符串。
# --hints--
`heart::after` 選擇器的 `background-color` 屬性值應爲 `pink`
```js
const heartAfter = code.match(/\.heart::after\s*{[\s\S]+?[^\}]}/g)[0];
assert(
/({|;)\s*background-color\s*:\s*pink\s*(;|})/g.test(heartAfter)
);
```
`heart::after` 僞元素的 `border-radius` 屬性值應爲 50%。
```js
assert(code.match(/border-radius\s*?:\s*?50%/gi).length == 2);
```
class 爲 `heart` 的元素的 `transform` 屬性應使用 `rotate()` 函數並傳入參數 -45 度。
```js
assert(code.match(/transform\s*?:\s*?rotate\(\s*?-45deg\s*?\)/gi));
```
`heart::before` 僞元素的 `content` 應爲空字符串。
```js
assert(code.match(/\.heart::before\s*?{\s*?content\s*?:\s*?("|')\1\s*?;/gi));
```
# --seed--
## --seed-contents--
```html
<style>
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: ;
}
.heart::after {
background-color: blue;
content: "";
border-radius: 25%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart::before {
content: ;
background-color: pink;
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
</style>
<div class="heart"></div>
```
# --solutions--
```html
<style>
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: rotate(-45deg);
}
.heart::after {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart::before {
content: "";
background-color: pink;
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
</style>
<div class="heart"></div>
```

View File

@ -0,0 +1,136 @@
---
id: 587d78a7367417b2b2512ae1
title: 使用 CSS 動畫創建動畫
challengeType: 0
videoUrl: 'https://scrimba.com/c/c7amZfW'
forumTopicId: 301051
dashedName: create-movement-using-css-animation
---
# --description--
在元素的 `position` 已有指定值(如 `fixed` 或者 `relative`CSS 偏移屬性 `right``left``top``bottom` 可以用在動畫規則裏創建動作。
就像下面的例子展示的那樣,你可以在 `50%` keyframe 處設置 `top` 屬性爲 50px在開始`0%`)和結束(`100%`keyframe 處設置爲 0px以實現元素先向下運動然後返回的動作效果。
```css
@keyframes rainbow {
0% {
background-color: blue;
top: 0px;
}
50% {
background-color: green;
top: 50px;
}
100% {
background-color: yellow;
top: 0px;
}
}
```
# --instructions--
請實現讓 `div` 水平運動的效果。 使用 `left` 偏移屬性,添加 `@keyframes` 規則,讓 rainbow 在 `0%` 處偏移 0px`50%` 處偏移 25px`100%` 處偏移 -25px。 不要修改編輯器裏的 `top` 屬性,元素應該同時在水平和豎直方向運動。
# --hints--
`0%``@keyframes` 規則應爲向 `left` 偏移 0px。
```js
assert(code.match(/[^50]0%\s*?{[\s\S]*?left:\s*?0px(;[\s\S]*?|\s*?)}/gi));
```
`50%``@keyframes` 規則應爲向 `left` 偏移 25px。
```js
assert(code.match(/50%\s*?{[\s\S]*?left:\s*?25px(;[\s\S]*?|\s*?)}/gi));
```
`100%``@keyframes` 規則應爲向 `left` 偏移 -25px。
```js
assert(code.match(/100%\s*?{[\s\S]*?left:\s*?-25px(;[\s\S]*?|\s*?)}/gi));
```
# --seed--
## --seed-contents--
```html
<style>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
position: relative;
}
#rect {
animation-name: rainbow;
animation-duration: 4s;
}
@keyframes rainbow {
0% {
background-color: blue;
top: 0px;
}
50% {
background-color: green;
top: 50px;
}
100% {
background-color: yellow;
top: 0px;
}
}
</style>
<div id="rect"></div>
```
# --solutions--
```html
<style>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
position: relative;
}
#rect {
animation-name: rainbow;
animation-duration: 4s;
}
@keyframes rainbow {
0% {
background-color: blue;
top: 0px;
left: 0px;
}
50% {
background-color: green;
top: 50px;
left: 25px;
}
100% {
background-color: yellow;
top: 0px;
left: -25px;
}
}
</style>
<div id="rect"></div>
```

View File

@ -0,0 +1,50 @@
---
id: 587d78a5367417b2b2512ad8
title: 通過添加細微圖案作爲背景圖像來創建紋理
challengeType: 0
videoUrl: 'https://scrimba.com/c/cQdwJC8'
forumTopicId: 301052
dashedName: create-texture-by-adding-a-subtle-pattern-as-a-background-image
---
# --description--
爲了增加背景圖的質感,我們可以爲它添加一個不那麼明顯的紋理圖案,這樣可以讓頁面更討喜。 但關鍵在於,我們需要找到一個平衡點,因爲我們不希望背景圖搶佔了內容的風頭,造成喧賓奪主的結果。 `background` 屬性支持使用 `url()` 函數作爲屬性值,這讓我們可以通過鏈接的方式引入紋理或樣式的圖片。 圖片鏈接的地址應寫在括號內,一般會用引號包起來。
# --instructions--
選取 `body` 元素,並設置整個頁面的 `background` 爲 url `https://cdn-media-1.freecodecamp.org/imgr/MJAkxbh.png` 的圖片。
# --hints--
`body` 元素選擇器應包含 `background` 屬性,且屬性值應爲給定的 `url`
```js
assert(
code.match(
/background:\s*?url\(\s*("|'|)https:\/\/cdn-media-1\.freecodecamp\.org\/imgr\/MJAkxbh\.png\1\s*\)/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
body {
}
</style>
```
# --solutions--
```html
<style>
body {
background: url("https://cdn-media-1.freecodecamp.org/imgr/MJAkxbh.png");
}
</style>
```

View File

@ -0,0 +1,118 @@
---
id: 587d7791367417b2b2512ab3
title: 使用 text-align 屬性創建視覺平衡
challengeType: 0
videoUrl: 'https://scrimba.com/c/c3b4EAp'
forumTopicId: 301053
dashedName: create-visual-balance-using-the-text-align-property
---
# --description--
這部分課程的主題是應用視覺設計。 開始的挑戰基於美化一個卡片組件的外觀,藉此展示了若干核心原則。
web 內容大部分都是文本。 CSS 裏面的 `text-align` 屬性可以控制文本的對齊方式。
`text-align: justify;` 可以讓除最後一行之外的文字兩端對齊,即每行的左右兩端都緊貼行的邊緣。
`text-align: center;` 可以讓文本居中對齊。
`text-align: right;` 可以讓文本右對齊。
`text-align: left;` 是默認值,它可以讓文本左對齊。
# --instructions--
請讓內容文本爲 “Google” 的 `h4` 標籤居中對齊, 然後將介紹 Google 創立歷程的段落文本兩端對齊。
# --hints--
`h4` 標籤應有值爲 `center` 的 text-align 屬性。
```js
assert($('h4').css('text-align') == 'center');
```
`p` 標籤應有值爲 `justify` 的 text-align 屬性。
```js
assert($('p').css('text-align') == 'justify');
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
}
p {
}
.links {
margin-right: 20px;
}
.fullCard {
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
}
p {
text-align: justify;
}
.links {
margin-right: 20px;
}
.fullCard {
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,95 @@
---
id: 587d78a7367417b2b2512ae2
title: 通過從左到右淡化元素來創建視覺方向
challengeType: 0
videoUrl: 'https://scrimba.com/c/cGJqqAE'
forumTopicId: 301054
dashedName: create-visual-direction-by-fading-an-element-from-left-to-right
---
# --description--
在本挑戰中,我們需要改變動畫元素的 `opacity` 屬性值,使其在到達屏幕右側時漸隱。
在示例動畫中,具有漸變背景的圓形元素在 `@keyframes` 爲 50% 的節點向右移動。
# --instructions--
使用 id 選擇器選擇 id 爲 `ball` 的元素,在 @keyframes`50%` 的節點裏添加 `opacity` 屬性並設置屬性值爲 0.1,使其在向右移動時漸隱。
# --hints--
`keyframes` 爲 50% 的節點處應設置 `opacity` 屬性值爲 0.1,以使其漸隱。
```js
assert(
code.match(
/@keyframes fade\s*?{\s*?50%\s*?{\s*?(?:left:\s*?60%;\s*?opacity:\s*?0?\.1;|opacity:\s*?0?\.1;\s*?left:\s*?60%;)/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
#ball {
width: 70px;
height: 70px;
margin: 50px auto;
position: fixed;
left: 20%;
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
animation-name: fade;
animation-duration: 3s;
}
@keyframes fade {
50% {
left: 60%;
}
}
</style>
<div id="ball"></div>
```
# --solutions--
```html
<style>
#ball {
width: 70px;
height: 70px;
margin: 50px auto;
position: fixed;
left: 20%;
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
animation-name: fade;
animation-duration: 3s;
}
@keyframes fade {
50% {
left: 60%;
opacity: 0.1;
}
}
</style>
<div id="ball"></div>
```

View File

@ -0,0 +1,134 @@
---
id: 587d781c367417b2b2512abf
title: 降低元素的透明度
challengeType: 0
videoUrl: 'https://scrimba.com/c/c7aKqu4'
forumTopicId: 301055
dashedName: decrease-the-opacity-of-an-element
---
# --description--
CSS 裏的 `opacity` 屬性用來設置元素的透明度。
<blockquote>屬性值爲 1 代表完全不透明。 <br>屬性值爲 0.5 代表半透明。 <br>屬性值爲 0 代表完全透明。</blockquote>
透明度會應用到元素內的所有內容,不論是圖片,還是文本,或是背景色。
# --instructions--
將 class 爲 `links` 的所有超鏈接的 `opacity` 屬性值設置 0.7。
# --hints--
應使用 `links` class 選擇所有的超鏈接,並設置其 `opacity` 屬性值爲 0.7。
```js
assert(
/\.links\s*{([\s\S]*?;)*\s*opacity\s*:\s*0*\.70*\s*(;[\s\S]*?|\s*)}/.test(
$('style').text()
)
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
#thumbnail {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard" id="thumbnail">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
opacity: 0.7;
}
#thumbnail {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard" id="thumbnail">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,90 @@
---
id: 587d78a3367417b2b2512ad1
title: 瞭解互補色
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MD3Tr'
forumTopicId: 301056
dashedName: learn-about-complementary-colors
---
# --description--
色彩理論以及設計色彩學很複雜,這裏將只涉及基礎部分。 在網站設計裏,顏色能讓內容更醒目,能調動情緒,從而創造舒適的視覺體驗。 不同的顏色組合對網站的視覺效果影響很大,精妙的設計都需要適宜的顏色來美化頁面內容。
色環是我們認識顏色關係的好工具。它是一個近色相鄰、異色相離的圓環。 當兩個顏色恰好在色環的兩端時,這兩個顏色就互爲補色。 兩個互爲補色的顏色會在混合後變成灰色。 然而,補色搭配能形成強烈的視覺對比效果。
下面是一些以 hex 形式表示的補色例子:
<blockquote>紅色(#FF0000)和藍綠色 (#00FFFF)<br>綠色(#00FF00)和品紅色(#FF00FF<br>藍色(#0000FF)和黃色(#FFFF00</blockquote>
這與我們許多人在學校學的過時的 RYB 色彩模式不同RYB 有不同的原色和補色。 現代色彩理論使用 RGB 模型(如在計算機屏幕上)和 CMYK模型如在印刷中。 在[這裏](https://en.wikipedia.org/wiki/Color_model)閱讀了解更多有關這個複雜主題的信息。
現在,很多在線選色工具也爲我們提供了尋找補色的功能。
**注意:**對於顏色相關的挑戰:顏色搭配是提起用戶興趣或吸引用戶注意的重要方式之一。 但我們不應讓顏色作爲傳達重要信息的唯一方式,因爲視覺障礙用戶可能無法像其他人一樣看出其中的含義。 我們將會在應用無障礙章節進行詳細介紹。
# --instructions--
把 class 爲 `blue``yellow` 的元素的 `background-color` 屬性改成相應的顏色。 注意觀察這兩個顏色的搭配效果,以及對比白色背景的視覺效果。
# --hints--
class 爲 `blue``div` 元素應有一個 `background-color`,顏色爲藍色。
```js
assert($('.blue').css('background-color') == 'rgb(0, 0, 255)');
```
class 爲 `yellow``div` 元素的 `background-color` 屬性,顏色爲黃色。
```js
assert($('.yellow').css('background-color') == 'rgb(255, 255, 0)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: #FFFFFF;
}
.blue {
background-color: #000000;
}
.yellow {
background-color: #000000;
}
div {
display: inline-block;
height: 100px;
width: 100px;
}
</style>
<div class="blue"></div>
<div class="yellow"></div>
```
# --solutions--
```html
<style>
body {
background-color: #FFFFFF;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
}
div {
display: inline-block;
height: 100px;
width: 100px;
}
</style>
<div class="blue"></div>
<div class="yellow"></div>
```

View File

@ -0,0 +1,114 @@
---
id: 587d78a4367417b2b2512ad2
title: 瞭解三次色
challengeType: 0
forumTopicId: 301057
dashedName: learn-about-tertiary-colors
---
# --description--
電腦顯示器和各類屏幕都是基於顏色疊加的模型將紅R、綠G、藍B三原色的色光以不同的比例相加就可以產生各種色彩光。 這在現代色彩理論中叫作三原色光模式RGB Color Model。 紅色R、綠色G和藍色B叫作三原色。 如果把兩種原色相加就可以產生二次色藍綠G+B、品紅R+B和黃色R+G 我們在上一個挑戰裏已經見過這些顏色了。 這些二次色恰好是在合成它們時未使用的原色的補色,即在色環中位於兩端。 例如,品紅色是紅色和藍色相加產生,它是綠色的補色。
三次色是由原色和二次色相加產生的顏色, 例如,在 RGB 顏色模型中,紅色(原色)和黃色(二次色)相加產生橙色(三次色)。 將這六種顏色中相鄰的顏色相加,便產生了十二色色環。
設計裏面有很多種顏色搭配方法。 涉及到三次色的一種配色方法是分裂補色搭配法。 選定主色之後,在色環上選擇與它的補色相鄰的兩種顏色與之搭配。 此種搭配既有對比,又不失和諧。
下面是使用分裂補色搭配法創建的三個顏色:
<table class='table table-striped'><thead><tr><th>顏色</th><th>HEX 顏色碼</th></tr></thead><thead></thead><tbody><tr><td>橙色</td><td>#FF7F00</td></tr><tr><td>藍綠色</td><td>#00FFFF</td></tr><tr><td>樹莓紅</td><td>#FF007F</td></tr></tbody></table>
# --instructions--
把 class 爲 `orange``cyan``raspberry``background-color` 改成其對應的顏色。 在這個挑戰中,請使用顏色的十六進制符號(即 hex code來表示。
# --hints--
class 爲 `orange``div``background-color` 屬性值應爲橙色。
```js
assert($('.orange').css('background-color') == 'rgb(255, 127, 0)');
```
class 爲 `cyan``div``background-color` 屬性值應爲藍綠色。
```js
assert($('.cyan').css('background-color') == 'rgb(0, 255, 255)');
```
class 爲 `raspberry``div``background-color` 屬性值應爲樹莓紅色。
```js
assert($('.raspberry').css('background-color') == 'rgb(255, 0, 127)');
```
所有的 `background-color` 應使用十六進制顏色碼,而不應使用顏色名稱。
```js
assert(!/background-color:\s(orange|cyan|raspberry)/.test(code));
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: #FFFFFF;
}
.orange {
background-color: #000000;
}
.cyan {
background-color: #000000;
}
.raspberry {
background-color: #000000;
}
div {
height: 100px;
width: 100px;
margin-bottom: 5px;
}
</style>
<div class="orange"></div>
<div class="cyan"></div>
<div class="raspberry"></div>
```
# --solutions--
```html
<style>
body {
background-color: #FFFFFF;
}
.orange {
background-color: #FF7F00;
}
.cyan {
background-color: #00FFFF;
}
.raspberry {
background-color: #FF007F;
}
div {
height: 100px;
width: 100px;
margin-bottom: 5px;
}
</style>
<div class="orange"></div>
<div class="cyan"></div>
<div class="raspberry"></div>
```

View File

@ -0,0 +1,136 @@
---
id: 587d78a9367417b2b2512ae8
title: 學習貝塞爾曲線的原理
challengeType: 0
videoUrl: 'https://scrimba.com/c/c9bDrs8'
forumTopicId: 301058
dashedName: learn-how-bezier-curves-work
---
# --description--
上一個挑戰中,我們介紹了 `animation-timing-function` 以及它的一些預設值,這些值定義了不同時間內的動畫速度。 除了預定義值之外CSS 還提供了貝塞爾曲線Bezier curves來更細緻地控制動畫的速度曲線。
在 CSS 動畫裏,我們可以用 `cubic-bezier` 來定義貝塞爾曲線。 曲線的形狀代表了動畫的速度。 曲線在 1 * 1 的座標系統內, 其中 X 軸代表動畫的時間間隔類似於時間比例尺Y 軸代表動畫的改變。
`cubic-bezier` 函數包含了 1 * 1 網格里的4個點`p0``p1``p2``p3`。 其中 `p0``p3` 是固定值,代表曲線的起始點和結束點,座標值依次爲 (0, 0) 和 (1, 1)。 你只需設置另外兩點的 x 值和 y 值,設置的這兩點確定了曲線的形狀從而確定了動畫的速度曲線。 在 CSS 裏面通過 `(x1, y1, x2, y2)` 來確定 `p1``p2`。 以下就是 CSS 貝塞爾曲線的例子:
```css
animation-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);
```
在上面的例子裏,兩個點的 x 和 y 值相等x1 = 0.25 = y1 和 x2 = 0.75 = y2。如果你還記得幾何課的知識結果是從原點到點 (1, 1) 的一條直線。 元素在動畫中的速度呈線性,效果和使用 `linear` 關鍵詞的效果一致。 換言之,元素勻速運動。
# --instructions--
對於 id 爲 `ball1` 的元素,把 `animation-timing-function` 屬性的值從 `linear` 改爲等價的 `cubic-bezier` 函數值。 也就是說使用上面例子給的值。
# --hints--
id 爲 `ball1` 的元素的 `animation-timing-function` 屬性值應該爲和 linear 預定值等價的 `cubic-bezier` 函數值。
```js
assert(
$('#ball1').css('animation-timing-function') ==
'cubic-bezier(0.25, 0.25, 0.75, 0.75)'
);
```
id 爲 `ball2` 的元素的 `animation-timing-function` 屬性值不應改變。
```js
const ball2Animation = __helpers.removeWhiteSpace(
$('#ball2').css('animation-timing-function')
);
assert(
ball2Animation == 'ease-out' || ball2Animation == 'cubic-bezier(0,0,0.58,1)'
);
```
# --seed--
## --seed-contents--
```html
<style>
.balls{
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#ball1 {
left: 27%;
animation-timing-function: linear;
}
#ball2 {
left: 56%;
animation-timing-function: ease-out;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id="ball1"></div>
<div class="balls" id="ball2"></div>
```
# --solutions--
```html
<style>
.balls{
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#ball1 {
left: 27%;
animation-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);
}
#ball2 {
left: 56%;
animation-timing-function: ease-out;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id="ball1"></div>
<div class="balls" id="ball2"></div>
```

View File

@ -0,0 +1,136 @@
---
id: 587d78a7367417b2b2512adf
title: 瞭解 CSS 的關鍵幀和動畫是如何工作的
challengeType: 0
videoUrl: 'https://scrimba.com/c/cakprhv'
forumTopicId: 301059
dashedName: learn-how-the-css-keyframes-and-animation-properties-work
---
# --description--
如果要給元素添加動畫,你需要了解 animation 屬性以及 `@keyframes` 規則。 animation 屬性控制動畫的外觀,`@keyframes` 規則控制動畫中各階段的變化。 總共有 8 個 animation 屬性。 爲了便於理解,本挑戰中我們只會暫時涉及到兩個最常用的屬性。
`animation-name` 用來設置動畫的名稱,也就是我們稍後要在 `@keyframes` 裏用到的名稱。
`animation-duration` 設置動畫所花費的時間。
`@keyframes` 可以通過設置特定時間點的行爲來創建動畫。 爲此,我們只需要給持續時間內的特定幀(從 0% 到 100%)加上 CSS 規則。 如果用一部電影來做類比,那麼 CSS 裏面的 0% 關鍵幀就像是電影裏面的開場鏡頭100% 關鍵幀就像是電影裏的片尾,就是那個之後會出現演職人員列表的片尾。 在動畫設定的時間內CSS 會根據關鍵幀的規則來給元素添加動畫效果。 100% 位置的 CSS 屬性就是元素最後的樣子,相當於電影裏的演職員表或者鳴謝鏡頭。 然後CSS 應用魔法來在給定的時間內轉換元素以使其脫離場景。 下面舉例說明 `@keyframes` 和動畫屬性的用法:
```css
#anim {
animation-name: colorful;
animation-duration: 3s;
}
@keyframes colorful {
0% {
background-color: blue;
}
100% {
background-color: yellow;
}
}
```
id 爲 `anim` 的元素,我們在代碼中將它的 `animation-name` 設置爲 `colorful`,同時設置 `animation-duration` 爲 3 秒。 然後我們把 `@keyframes` 規則添加到名爲 `colorful` 的動畫屬性上。 在動畫開始時0%的背景顏色爲藍色在動畫結束時100%)的背景顏色爲黃色。 注意我們不只可以設置開始和結束,而是從 0% 到 100% 間的任意位置都可以設置。
# --instructions--
給 id 爲 `rect` 的元素添加動畫,設置其 `animation-name``rainbow`,設置其 `animation-duration` 爲 4 秒。 然後聲明 `@keyframes` 規則,設置動畫開始時(`0%`)的 `background-color` 爲藍色,動畫中間時(`50%`)爲綠色,動畫結束時(`100%`)爲爲黃色。
# --hints--
id 爲 `rect` 的元素應該有一個值爲 `rainbow``animation-name` 屬性。
```js
assert($('#rect').css('animation-name') == 'rainbow');
```
id 爲 `rect` 的元素應該有一個值爲 4s 的 `animation-duration` 屬性。
```js
assert($('#rect').css('animation-duration') == '4s');
```
`@keyframes` 規則的 `animation-name` 應爲 `rainbow`
```js
assert(code.match(/@keyframes\s+?rainbow\s*?{/g));
```
`@keyframes` 規則的 `rainbow` 在 0% 時的 `background-color` 應爲 `blue`
```js
assert(code.match(/0%\s*?{\s*?background-color:\s*?blue;\s*?}/gi));
```
`@keyframes` 規則的 `rainbow` 在 50% 時的 `background-color` 應爲 `green`
```js
assert(code.match(/50%\s*?{\s*?background-color:\s*?green;\s*?}/gi));
```
`@keyframes` 規則的 rainbow 在 100% 時的 `background-color` 應爲 `yellow`
```js
assert(code.match(/100%\s*?{\s*?background-color:\s*?yellow;\s*?}/gi));
```
# --seed--
## --seed-contents--
```html
<style>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
}
#rect {
}
</style>
<div id="rect"></div>
```
# --solutions--
```html
<style>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
}
#rect {
animation-name: rainbow;
animation-duration: 4s;
}
@keyframes rainbow {
0% {
background-color: blue;
}
50% {
background-color: green;
}
100% {
background-color: yellow;
}
}
</style>
<div id="rect"></div>
```

View File

@ -0,0 +1,90 @@
---
id: 587d781e367417b2b2512acb
title: 絕對定位的參照物是元素的父元素
challengeType: 0
videoUrl: 'https://scrimba.com/c/cyLJ7c3'
forumTopicId: 301060
dashedName: lock-an-element-to-its-parent-with-absolute-positioning
---
# --description--
接下來要介紹 CSS `position` 屬性的取值選項 `absolute`,它的含義是相對於其包含塊定位。 和 `relative` 定位不一樣,絕對定位會將元素從當前的文檔流裏面移除,周圍的元素會忽略它。 這樣我們就可以用 CSS 的 top、bottom、left、right 屬性來調整元素的位置。
絕對定位比較特殊的一點是元素的定位參照於最近的 *positioned* 祖先元素。 如果它的父元素沒有添加定位規則(默認是 `position: relative;`),瀏覽器會繼續尋找直到默認的 `body` 標籤。
# --instructions--
通過設置 `position` 屬性值爲 `absolute`,將 `#searchbar` 元素固定到它的父元素 `section` 的右上角。 即設定其 `top``right` 爲 50 像素。
# --hints--
`#searchbar` 元素的 `position` 屬性值應爲 `absolute`
```js
assert($('#searchbar').css('position') == 'absolute');
```
`#searchbar` 元素的 `top` 屬性值應爲 50px。
```js
assert($('#searchbar').css('top') == '50px');
```
`#searchbar` 元素的 `right` 屬性值應爲 50px。
```js
assert($('#searchbar').css('right') == '50px');
```
# --seed--
## --seed-contents--
```html
<style>
#searchbar {
}
section {
position: relative;
}
</style>
<body>
<h1>Welcome!</h1>
<section>
<form id="searchbar">
<label for="search">Search:</label>
<input type="search" id="search" name="search">
<input type="submit" name="submit" value="Go!">
</form>
</section>
</body>
```
# --solutions--
```html
<style>
#searchbar {
position: absolute;
top: 50px;
right: 50px;
}
section {
position: relative;
}
</style>
<body>
<h1>Welcome!</h1>
<section>
<form id="searchbar">
<label for="search">Search:</label>
<input type="search" id="search" name="search">
<input type="submit" name="submit" value="Go!">
</form>
</section>
</body>
```

View File

@ -0,0 +1,120 @@
---
id: 587d781e367417b2b2512acc
title: 固定定位的參照物是瀏覽器的窗口
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MDNUR'
forumTopicId: 301061
dashedName: lock-an-element-to-the-browser-window-with-fixed-positioning
---
# --description--
接下來要介紹的是 `fixed` 定位它是一種特殊的絕對absolute定位將元素相對於瀏覽器窗口定位。 類似於絕對位置,它與 CSS 偏移屬性一起使用,並且也會將元素從當前的文檔流裏面移除。 其它元素會忽略它的存在,這樣也許需要調整其他位置的佈局。
`fixed``absolute` 的最明顯的區別在於,前者定位的元素不會隨着屏幕滾動而移動。
# --instructions--
我們已經將代碼裏導航欄的 id 設置爲了 `navbar`。 請把它的 `position` 設置成 `fixed`,同時分別設定其 `top``left` 屬性值爲 0 像素。 修改後,你可以滑動預覽窗口,觀察導航欄的位置。
# --hints--
`#navbar` 元素的 `position` 屬性值應爲 `fixed`
```js
assert($('#navbar').css('position') == 'fixed');
```
`#navbar` 元素的 `top` 屬性值應爲 0px。
```js
assert($('#navbar').css('top') == '0px');
```
`#navbar` 元素的 `left` 屬性值應爲 0px。
```js
assert($('#navbar').css('left') == '0px');
```
# --seed--
## --seed-contents--
```html
<style>
body {
min-height: 150vh;
}
#navbar {
width: 100%;
background-color: #767676;
}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;
}
nav li {
display: inline;
margin-right: 20px;
}
a {
text-decoration: none;
}
</style>
<body>
<header>
<h1>Welcome!</h1>
<nav id="navbar">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
</header>
<p>I shift up when the #navbar is fixed to the browser window.</p>
</body>
```
# --solutions--
```html
<style>
body {
min-height: 150vh;
}
#navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #767676;
}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;
}
nav li {
display: inline;
margin-right: 20px;
}
a {
text-decoration: none;
}
</style>
<body>
<header>
<h1>Welcome!</h1>
<nav id="navbar">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
</header>
<p>I shift up when the #navbar is fixed to the browser window.</p>
</body>
```

View File

@ -0,0 +1,181 @@
---
id: 587d78a8367417b2b2512ae4
title: 使用無限的動畫計數製作 CSS 心跳
challengeType: 0
videoUrl: 'https://scrimba.com/c/cDZpDUr'
forumTopicId: 301062
dashedName: make-a-css-heartbeat-using-an-infinite-animation-count
---
# --description--
這也是一個用 `animation-iteration-count` 屬性創造持續動畫的例子,它基於我們在前面挑戰中創建的心形。
心跳動畫的每一秒包含兩個部分。 `heart` 元素(包括 `:before``:after`)使用 `transform` 屬性改變其大小,背景 `div` 使用 `background` 屬性改變其顏色。
# --instructions--
`back` class 和 the `heart` class 添加 `animation-iteration-count` 屬性,將屬性值設置爲 `infinite`,使心保持跳動。 `heart:before``heart:after` 所選擇的元素則不需要添加動畫屬性。
# --hints--
`heart` class 的 `animation-iteration-count` 的屬性值應爲 `infinite`
```js
assert($('.heart').css('animation-iteration-count') == 'infinite');
```
`back` class 的 `animation-iteration-count` 的屬性值應爲 `infinite`
```js
assert($('.back').css('animation-iteration-count') == 'infinite');
```
# --seed--
## --seed-contents--
```html
<style>
.back {
position: fixed;
padding: 0;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: white;
animation-name: backdiv;
animation-duration: 1s;
}
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: rotate(-45deg);
animation-name: beat;
animation-duration: 1s;
}
.heart:after {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart:before {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
@keyframes backdiv {
50% {
background: #ffe6f2;
}
}
@keyframes beat {
0% {
transform: scale(1) rotate(-45deg);
}
50% {
transform: scale(0.6) rotate(-45deg);
}
}
</style>
<div class="back"></div>
<div class="heart"></div>
```
# --solutions--
```html
<style>
.back {
position: fixed;
padding: 0;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: white;
animation-name: backdiv;
animation-duration: 1s;
animation-iteration-count: infinite;
}
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: rotate(-45deg);
animation-name: beat;
animation-duration: 1s;
animation-iteration-count: infinite;
}
.heart:after {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart:before {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
@keyframes backdiv {
50% {
background: #ffe6f2;
}
}
@keyframes beat {
0% {
transform: scale(1) rotate(-45deg);
}
50% {
transform: scale(0.6) rotate(-45deg);
}
}
</style>
<div class="back"></div>
<div class="heart"></div>
```

View File

@ -0,0 +1,121 @@
---
id: 587d78a9367417b2b2512aea
title: 使用貝塞爾曲線讓運動更加自然
challengeType: 0
videoUrl: 'https://scrimba.com/c/c7akWUv'
forumTopicId: 301063
dashedName: make-motion-more-natural-using-a-bezier-curve
---
# --description--
在這個挑戰中,我們需要給元素添加動畫來模擬雜耍中被拋接的球。 之前的挑戰中,我們學習了 `linear``ease-out` 的貝塞爾曲線描述,但這兩個都無法完美地描述雜耍球的運動。 在本關裏你需要定製貝塞爾曲線。
`animation-iteration-count` 值爲 infinite 時,`animation-timing-function` 會自動循環 keyframe。 由於我們是在動畫週期的中間點(`50%` 處)設置的 keyframe 規則,最終的結果是球向上和球向下是兩個同樣的動畫過程。
下面的例子模擬了雜耍球運動:
```css
cubic-bezier(0.3, 0.4, 0.5, 1.6);
```
注意 y2 的值是大於 1 的。 雖然貝塞爾曲線是在 1*1 的座標系統內x 值只能在 0 到 1但是 y 值是可以大於 1 的。 這樣才能模擬雜耍球運動。
# --instructions--
把 id 爲 `green` 的元素的 `animation-timing-function` 值改成 `cubic-bezier` 函數,函數的參數 x1y1x2y2 值依次爲 0.311、0.441、0.444、1.649。
# --hints--
id 爲 `green` 的元素的 `animation-timing-function` 值應爲 `cubic-bezier` 函數,函數的參數 x1y1x2y2 值應爲指定值。
```js
assert(
$('#green').css('animation-timing-function') ==
'cubic-bezier(0.311, 0.441, 0.444, 1.649)'
);
```
# --seed--
## --seed-contents--
```html
<style>
.balls {
border-radius: 50%;
position: fixed;
width: 50px;
height: 50px;
top: 60%;
animation-name: jump;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#red {
background: red;
left: 25%;
animation-timing-function: linear;
}
#blue {
background: blue;
left: 50%;
animation-timing-function: ease-out;
}
#green {
background: green;
left: 75%;
animation-timing-function: cubic-bezier(0.69, 0.1, 1, 0.1);
}
@keyframes jump {
50% {
top: 10%;
}
}
</style>
<div class="balls" id="red"></div>
<div class="balls" id="blue"></div>
<div class="balls" id="green"></div>
```
# --solutions--
```html
<style>
.balls {
border-radius: 50%;
position: fixed;
width: 50px;
height: 50px;
top: 60%;
animation-name: jump;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#red {
background: red;
left: 25%;
animation-timing-function: linear;
}
#blue {
background: blue;
left: 50%;
animation-timing-function: ease-out;
}
#green {
background: green;
left: 75%;
animation-timing-function: cubic-bezier(0.311, 0.441, 0.444, 1.649);
}
@keyframes jump {
50% {
top: 10%;
}
}
</style>
<div class="balls" id="red"></div>
<div class="balls" id="blue"></div>
<div class="balls" id="green"></div>
```

View File

@ -0,0 +1,92 @@
---
id: 58a7a6ebf9a6318348e2d5aa
title: 修改動畫的填充模式
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJDmcE'
forumTopicId: 301064
dashedName: modify-fill-mode-of-an-animation
---
# --description--
太棒了,但是現在還不完美。 注意動畫在 `500ms` 之後重置了,所以按鈕又變成了之前的顏色。 而我們想要的效果是按鈕在懸停時始終高亮。
爲此,我們可以通過把 `animation-fill-mode` 設置成 `forwards` 來實現。 `animation-fill-mode` 指定了在動畫結束時元素的樣式: 你可以這樣設置:
```css
animation-fill-mode: forwards;
```
# --instructions--
設置 `button:hover``animation-fill-mode` 屬性爲 `forwards`,使用戶把鼠標懸停在按鈕上時,按鈕保持高亮。
# --hints--
`button:hover` 應有一個值爲 `forwards``animation-fill-mode` 屬性。
```js
assert(
code.match(
/button\s*?:\s*?hover\s*?{[\s\S]*animation-fill-mode\s*?:\s*?forwards\s*?;[\s\S]*}/gi
) &&
code.match(
/button\s*?:\s*?hover\s*?{[\s\S]*animation-name\s*?:\s*?background-color\s*?;[\s\S]*}/gi
) &&
code.match(
/button\s*?:\s*?hover\s*?{[\s\S]*animation-duration\s*?:\s*?500ms\s*?;[\s\S]*}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
button {
border-radius: 5px;
color: white;
background-color: #0F5897;
padding: 5px 10px 8px 10px;
}
button:hover {
animation-name: background-color;
animation-duration: 500ms;
/* Only change code below this line */
/* Only change code above this line */
}
@keyframes background-color {
100% {
background-color: #4791d0;
}
}
</style>
<button>Register</button>
```
# --solutions--
```html
<style>
button {
border-radius: 5px;
color: white;
background-color: #0F5897;
padding: 5px 10px 8px 10px;
}
button:hover {
animation-name: background-color;
animation-duration: 500ms;
animation-fill-mode: forwards;
}
@keyframes background-color {
100% {
background-color: #4791d0;
}
}
</style>
<button>Register</button>
```

View File

@ -0,0 +1,72 @@
---
id: 587d781e367417b2b2512aca
title: 使用 CSS 偏移移動相對定位的元素
challengeType: 0
videoUrl: 'https://scrimba.com/c/c9bQEA4'
forumTopicId: 301065
dashedName: move-a-relatively-positioned-element-with-css-offsets
---
# --description--
CSS 裏面的 `top``bottom``left``right` 定義了元素在相應方位的偏移距離。 元素將從當前位置向屬性相反的方向偏移。 就像你在上一個挑戰看到的,`top` 屬性使 `h2` 向下移動。 同樣,使用 `left` 將項目移動到右邊。
<img src='https://i.imgur.com/eWWi3gZ.gif' alt='' />
# --instructions--
請通過 CSS 屬性把 `h2` 向上移動 10 像素,向右移動 15 像素。
# --hints--
應使用 CSS 屬性使 `h2` 相對當前位置向上移動 10px。 也就是說,從當前位置相對於 `bottom` 移動 10px。
```js
assert($('h2').css('bottom') == '10px');
```
應使用 CSS 屬性使 `h2` 相對當前位置向右移動 15px。 也就是說,從當前位置相對於 `left` 移動 15px。
```js
assert($('h2').css('left') == '15px');
```
# --seed--
## --seed-contents--
```html
<head>
<style>
h2 {
position: relative;
}
</style>
</head>
<body>
<h1>On Being Well-Positioned</h1>
<h2>Move me!</h2>
<p>I still think the h2 is where it normally sits.</p>
</body>
```
# --solutions--
```html
<head>
<style>
h2 {
position: relative;
left: 15px;
bottom: 10px;
}
</style>
</head>
<body>
<h1>On Being Well-Positioned</h1>
<h2>Move me!</h2>
<p>I still think the h2 is where it normally sits.</p>
</body>
```

View File

@ -0,0 +1,100 @@
---
id: 587d78a3367417b2b2512ace
title: 使用 float 屬性將元素左浮動或右浮動
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MDqu2'
forumTopicId: 301066
dashedName: push-elements-left-or-right-with-the-float-property
---
# --description--
接下來要介紹的定位機制並不是 `position` 屬性的選項,而是通過元素的 `float` 屬性來設置。 浮動元素不在文檔流中,它向 `left``right` 浮動,直到它的外邊緣碰到包含框或另一個浮動框的邊框爲止。 通常需要用 `width` 屬性來指定浮動元素佔據的水平空間。
# --instructions--
使這兩個元素按兩列布局,`section``aside` 左右排列。 設置 `#left` 元素的 `float` 屬性值爲 `left`,設置 `#right` 元素的 `float` 屬性值爲 `right`
# --hints--
id 爲 `left` 的元素的 `float` 屬性值應爲 `left`
```js
assert($('#left').css('float') == 'left');
```
id 爲 `right` 的元素的 `float` 屬性值應爲 `right`
```js
assert($('#right').css('float') == 'right');
```
# --seed--
## --seed-contents--
```html
<head>
<style>
#left {
width: 50%;
}
#right {
width: 40%;
}
aside, section {
padding: 2px;
background-color: #ccc;
}
</style>
</head>
<body>
<header>
<h1>Welcome!</h1>
</header>
<section id="left">
<h2>Content</h2>
<p>Good stuff</p>
</section>
<aside id="right">
<h2>Sidebar</h2>
<p>Links</p>
</aside>
</body>
```
# --solutions--
```html
<head>
<style>
#left {
float: left;
width: 50%;
}
#right {
float: right;
width: 40%;
}
aside, section {
padding: 2px;
background-color: #ccc;
}
</style>
</head>
<body>
<header>
<h1>Welcome!</h1>
</header>
<section id="left">
<h2>Content</h2>
<p>Good stuff</p>
</section>
<aside id="right">
<h2>Sidebar</h2>
<p>Links</p>
</aside>
</body>
```

View File

@ -0,0 +1,114 @@
---
id: 587d781c367417b2b2512ac2
title: 設置多個標題元素的 font-size
challengeType: 0
videoUrl: 'https://scrimba.com/c/cPpQNT3'
forumTopicId: 301067
dashedName: set-the-font-size-for-multiple-heading-elements
---
# --description--
`font-size` 屬性用來指定元素內文字的大小。 我們可以爲多個元素添加這個規則,讓頁面內不同元素的文字大小得以統一。 在本挑戰裏,你需要設置從 `h1``h6` 的文字大小。
# --instructions-- <p>在 <code>style</code> 標籤中, 對各元素的 <code>font-size</code> 進行如下設置:</p>
<ul>
<li><code>h1</code> 標籤的文字大小設爲 68px。</li>
<li><code>h2</code> 標籤的文字大小設爲 52px。</li>
<li><code>h3</code> 標籤的文字大小設爲 40px</li>
<li><code>h4</code> 標籤的文字大小設爲 32px</li>
<li><code>h5</code> 標籤的文字大小設爲 21px</li>
<li><code>h6</code> 標籤的文字大小設爲 14px</li>
</ul>
# --hints--
`h1` 標籤的 `font-size` 屬性值應爲 68px。
```js
assert($('h1').css('font-size') == '68px');
```
`h2` 標籤的 `font-size` 屬性值應爲 52px。
```js
assert($('h2').css('font-size') == '52px');
```
`h3` 標籤的 `font-size` 屬性值應爲 40px。
```js
assert($('h3').css('font-size') == '40px');
```
`h4` 標籤的 `font-size` 屬性值應爲 32px。
```js
assert($('h4').css('font-size') == '32px');
```
`h5` 標籤的 `font-size` 屬性值應爲 21px。
```js
assert($('h5').css('font-size') == '21px');
```
`h6` 標籤的 `font-size` 屬性值應爲 14px。
```js
const regex = /h6\s*\{\s*font-size\s*:\s*14px\s*(;\s*\}|\})/i;
assert.strictEqual(true, regex.test(code));
```
# --seed--
## --seed-contents--
```html
<style>
</style>
<h1>This is h1 text</h1>
<h2>This is h2 text</h2>
<h3>This is h3 text</h3>
<h4>This is h4 text</h4>
<h5>This is h5 text</h5>
<h6>This is h6 text</h6>
```
# --solutions--
```html
<style>
h1 {
font-size: 68px;
}
h2 {
font-size: 52px;
}
h3 {
font-size: 40px;
}
h4 {
font-size: 32px;
}
h5 {
font-size: 21px;
}
h6 {
font-size: 14px;
}
</style>
<h1>This is h1 text</h1>
<h2>This is h2 text</h2>
<h3>This is h3 text</h3>
<h4>This is h4 text</h4>
<h5>This is h5 text</h5>
<h6>This is h6 text</h6>
```

View File

@ -0,0 +1,52 @@
---
id: 587d781c367417b2b2512ac4
title: 設置段落文本的 font-size
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJ36Cr'
forumTopicId: 301068
dashedName: set-the-font-size-of-paragraph-text
---
# --description--
CSS 裏面的 `font-size` 屬性不只限於標題,還可以應用於任何包含文字的元素內。
# --instructions--
把段落的 `font-size` 屬性值設置爲 16px讓它看起來更清晰。
# --hints--
`p` 標籤的 `font-size` 屬性值應爲 16px。
```js
assert($('p').css('font-size') == '16px');
```
# --seed--
## --seed-contents--
```html
<style>
p {
font-size: 10px;
}
</style>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</p>
```
# --solutions--
```html
<style>
p {
font-size: 16px;
}
</style>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</p>
```

View File

@ -0,0 +1,132 @@
---
id: 587d781c367417b2b2512ac3
title: 設置多個標題元素的 font-weight
challengeType: 0
videoUrl: 'https://scrimba.com/c/crVWRHq'
forumTopicId: 301069
dashedName: set-the-font-weight-for-multiple-heading-elements
---
# --description--
在上一個挑戰裏我們已經爲每個標題設置了 `font-size`,接下來我們將要設置 `font-weight`
`font-weight` 屬性用於設置文本中字體的粗細。
# --instructions--
<ul><li>設置 <code>h1</code> 標籤的 <code>font-weight</code> 爲 800。</li><li>設置 <code>h2</code> 標籤的 <code>font-weight</code> 爲 600。</li><li>設置 <code>h3</code> 標籤的 <code>font-weight</code> 爲 500。</li><li>設置 <code>h4</code> 標籤的 <code>font-weight</code> 爲 400。</li><li>設置 <code>h5</code> 標籤的 <code>font-weight</code> 爲 300。</li><li>設置 <code>h6</code> 標籤的 <code>font-weight</code> 爲 200。</li></ul>
# --hints--
`h1` 標籤的 `font-weight` 屬性值應爲 800。
```js
assert($('h1').css('font-weight') == '800');
```
`h2` 標籤的 `font-weight` 屬性值應爲 600。
```js
assert($('h2').css('font-weight') == '600');
```
`h3` 標籤的 `font-weight` 屬性值應爲 500。
```js
assert($('h3').css('font-weight') == '500');
```
`h4` 標籤的 `font-weight` 屬性值應爲 400。
```js
assert($('h4').css('font-weight') == '400');
```
`h5` 標籤的 `font-weight` 屬性值應爲 300。
```js
assert($('h5').css('font-weight') == '300');
```
`h6` 標籤的 `font-weight` 屬性值應爲 200。
```js
assert($('h6').css('font-weight') == '200');
```
# --seed--
## --seed-contents--
```html
<style>
h1 {
font-size: 68px;
}
h2 {
font-size: 52px;
}
h3 {
font-size: 40px;
}
h4 {
font-size: 32px;
}
h5 {
font-size: 21px;
}
h6 {
font-size: 14px;
}
</style>
<h1>This is h1 text</h1>
<h2>This is h2 text</h2>
<h3>This is h3 text</h3>
<h4>This is h4 text</h4>
<h5>This is h5 text</h5>
<h6>This is h6 text</h6>
```
# --solutions--
```html
<style>
h1 {
font-size: 68px;
font-weight: 800;
}
h2 {
font-size: 52px;
font-weight: 600;
}
h3 {
font-size: 40px;
font-weight: 500;
}
h4 {
font-size: 32px;
font-weight: 400;
}
h5 {
font-size: 21px;
font-weight: 300;
}
h6 {
font-size: 14px;
font-weight: 200;
}
</style>
<h1>This is h1 text</h1>
<h2>This is h2 text</h2>
<h3>This is h3 text</h3>
<h4>This is h4 text</h4>
<h5>This is h5 text</h5>
<h6>This is h6 text</h6>
```

View File

@ -0,0 +1,54 @@
---
id: 587d781d367417b2b2512ac5
title: 設置段落的 line-height
challengeType: 0
videoUrl: 'https://scrimba.com/c/crVWdcv'
forumTopicId: 301070
dashedName: set-the-line-height-of-paragraphs
---
# --description--
CSS 提供 `line-height` 屬性來設置行間的距離。 行高,顧名思義,可以用來設置每行文字所佔據的垂直空間。
# --instructions--
`p` 標籤添加 `line-height` 屬性並賦值 25px。
# --hints--
`p` 標籤的 `line-height` 屬性值應爲 25px。
```js
assert($('p').css('line-height') == '25px');
```
# --seed--
## --seed-contents--
```html
<style>
p {
font-size: 16px;
}
</style>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</p>
```
# --solutions--
```html
<style>
p {
font-size: 16px;
line-height: 25px;
}
</style>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</p>
```

View File

@ -0,0 +1,128 @@
---
id: 587d78a9367417b2b2512ae9
title: 使用貝塞爾曲線移動圖形
challengeType: 0
videoUrl: 'https://scrimba.com/c/c6bnRCK'
forumTopicId: 301071
dashedName: use-a-bezier-curve-to-move-a-graphic
---
# --description--
前面的關卡涉及了使用 `ease-out` 預定義值描述了動畫以高速開始低速結束。 右邊的動畫展示了 `ease-out` 效果(藍色的元素)和 `linear` 效果(紅色的元素)的區別。 同樣的,`ease-out` 預定義值也可以用貝塞爾曲線函數實現。
通俗的講,將一條直線放在範圍只有 1 的座標軸中,並從中間拿 `p1``p2` 兩個點來拉扯X 軸的取值區間是 \[0, 1]Y 軸任意),最後形成的曲線就是動畫的貝塞爾速度曲線。 下面是貝塞爾曲線模仿 ease-out 預定義值的例子:
```css
animation-timing-function: cubic-bezier(0, 0, 0.58, 1);
```
記住所有的 `cubic-bezier` 函數都是從座標爲 (0, 0) 的 `p0` 開始,在座標爲 (1, 1) 的 `p3` 結束。 在這個例子裏,曲線在 y 軸(從 0 開始,運動到 `p1` 的 0然後運動到 `p2` 的 1上移動得比在 x 軸(從 0 開始,運動到 `p1` 的 0`p2` 的 0.58)上移動得快。 結果是,在這一段動畫內元素運動得快。 到曲線的結尾x 和 y 之間的關係反過來了y 值保持爲 1沒有變化x 值從 0.58 變爲 1元素運動得慢。
# --instructions--
爲了看貝塞爾曲線的運動效果,把 id 爲 `red` 的元素的 `animation-timing-function` 屬性改爲 `cubic-bezier` 函數,其中 x1y1x2y2 值分別爲 0、0、0.58、1。 這會使兩個元素運動過程類似。
# --hints--
id 爲 `red` 的元素的 `animation-timing-function` 屬性應爲 `cubic-bezier` 函數,其中 x1、y1、x2、y2 值分別爲 0、0、0.58、1。
```js
assert(
$('#red').css('animation-timing-function') == 'cubic-bezier(0, 0, 0.58, 1)'
);
```
id 爲 `red` 的元素不應有值爲 `linear``animation-timing-function` 屬性。
```js
assert($('#red').css('animation-timing-function') !== 'linear');
```
id 爲 `blue` 的元素的 `animation-timing-function` 屬性值不應該改變。
```js
const blueBallAnimation = __helpers.removeWhiteSpace(
$('#blue').css('animation-timing-function')
);
assert(
blueBallAnimation == 'ease-out' ||
blueBallAnimation == 'cubic-bezier(0,0,0.58,1)'
);
```
# --seed--
## --seed-contents--
```html
<style>
.balls{
border-radius: 50%;
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#red {
background: red;
left: 27%;
animation-timing-function: linear;
}
#blue {
background: blue;
left: 56%;
animation-timing-function: ease-out;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id= "red"></div>
<div class="balls" id= "blue"></div>
```
# --solutions--
```html
<style>
.balls{
border-radius: 50%;
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#red {
background: red;
left: 27%;
animation-timing-function: cubic-bezier(0, 0, 0.58, 1);
}
#blue {
background: blue;
left: 56%;
animation-timing-function: ease-out;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id= "red"></div>
<div class="balls" id= "blue"></div>
```

View File

@ -0,0 +1,113 @@
---
id: 587d78a5367417b2b2512ad7
title: 使用 CSS 線性漸變創建條紋元素
challengeType: 0
videoUrl: 'https://scrimba.com/c/c6bmQh2'
forumTopicId: 301072
dashedName: use-a-css-linear-gradient-to-create-a-striped-element
---
# --description--
`repeating-linear-gradient()` 函數和 `linear-gradient()` 很像,主要區別是前者會重複指定的漸變。 `repeating-linear-gradient()` 有很多參數,爲了便於理解,本關只用到角度值和色標。
角度就是漸變的方向。 色標代表漸變顏色及發生漸變的位置,由百分比或者像素值表示。
在代碼編輯器的例子裏,漸變開始於 0 像素位置的 `yellow`,然後過渡到距離開始位置 40 像素的 `blue`。 由於下一個漸變顏色的起始位置也是 40 像素,所以顏色直接漸變成第三個顏色值 `green`,然後過渡到距離開始位置 80 像素的 `red`
下面的代碼可以幫助理解成對的起止漸變顏色值是如何過渡的。
```css
0px [yellow -- blend -- blue] 40px [green -- blend -- red] 80px
```
如果每對起止漸變顏色值的顏色都是相同的,由於是在兩個相同的顏色間過渡,那麼中間的過渡色也爲同色,接着就是同色的過渡色和下一個起止顏色,最終產生的效果就是條紋。
# --instructions--
使用 `repeating-linear-gradient()` 函數創建一個漸變角度爲 `45deg` 的條紋,然後設置第一對漸變顏色爲 `yellow`,第二對漸變顏色爲 `black`
# --hints--
`repeating-linear-gradient()` 的漸變角度應爲 45deg。
```js
assert(code.match(/background:\s*?repeating-linear-gradient\(\s*?45deg/gi));
```
`repeating-linear-gradient()` 的漸變角度應該不再是 90deg。
```js
assert(!code.match(/90deg/gi));
```
0px 處的漸變顏色應該是 `yellow`
```js
assert(code.match(/yellow\s+?0(px)?/gi));
```
40px 處的一個漸變顏色應該是 `yellow`
```js
assert(code.match(/yellow\s+?40px/gi));
```
40px 處的第二個漸變顏色應該是 `black`
```js
assert(code.match(/yellow\s+?40px,\s*?black\s+?40px/gi));
```
80px 處的最後一個漸變顏色應該是 `black`
```js
assert(code.match(/black\s+?80px/gi));
```
# --seed--
## --seed-contents--
```html
<style>
div{
border-radius: 20px;
width: 70%;
height: 400px;
margin: 50 auto;
background: repeating-linear-gradient(
90deg,
yellow 0px,
blue 40px,
green 40px,
red 80px
);
}
</style>
<div></div>
```
# --solutions--
```html
<style>
div{
border-radius: 20px;
width: 70%;
height: 400px;
margin: 50 auto;
background: repeating-linear-gradient(
45deg,
yellow 0px,
yellow 40px,
black 40px,
black 80px
);
}
</style>
<div></div>
```

View File

@ -0,0 +1,100 @@
---
id: 587d78a7367417b2b2512ae0
title: 使用CSS動畫更改按鈕的懸停狀態
challengeType: 0
videoUrl: 'https://scrimba.com/c/cg4vZAa'
forumTopicId: 301073
dashedName: use-css-animation-to-change-the-hover-state-of-a-button
---
# --description--
你可以在按鈕懸停時使用 `@keyframes` 改變按鈕的顏色。
下面是在圖片懸停時改變圖片寬度的例子:
```html
<style>
img:hover {
animation-name: width;
animation-duration: 500ms;
}
@keyframes width {
100% {
width: 40px;
}
}
</style>
<img src="https://bit.ly/smallgooglelogo" alt="Google's Logo" />
```
# --instructions--
注意 `ms` 代表毫秒1000ms 等於 1s。
使用 `@keyframes` 來改變 `button` 元素的 `background-color`,使其在懸停時變成 `#4791d0``@keyframes` 規則應該只有一個 `100%` 條目。
# --hints--
@keyframes 規則的 `animation-name` 應該是 background-color。
```js
assert(code.match(/@keyframes\s+?background-color\s*?{/g));
```
`@keyframes` 爲 100% 的位置,應將 `background-color` 改成 `#4791d0`
```js
assert(code.match(/100%\s*?{\s*?background-color:\s*?#4791d0;\s*?}/gi));
```
# --seed--
## --seed-contents--
```html
<style>
button {
border-radius: 5px;
color: white;
background-color: #0F5897;
padding: 5px 10px 8px 10px;
}
button:hover {
animation-name: background-color;
animation-duration: 500ms;
}
</style>
<button>Register</button>
```
# --solutions--
```html
<style>
button {
border-radius: 5px;
color: white;
background-color: #0F5897;
padding: 5px 10px 8px 10px;
}
button:hover {
animation-name: background-color;
animation-duration: 500ms;
}
@keyframes background-color {
100% {
background-color: #4791d0;
}
}
</style>
<button>Register</button>
```

View File

@ -0,0 +1,77 @@
---
id: 587d78a6367417b2b2512adb
title: 使用 CSS Transform skex 屬性沿X軸傾斜元素
challengeType: 0
videoUrl: 'https://scrimba.com/c/cyLP8Sr'
forumTopicId: 301074
dashedName: use-the-css-transform-property-skewx-to-skew-an-element-along-the-x-axis
---
# --description--
接下來要介紹的 `transform` 屬性是 `skewX()`:它使選擇的元素沿着 X 軸(橫向)翻轉指定的角度。
下面的代碼沿着 X 軸翻轉段落元素 -32 度。
```css
p {
transform: skewX(-32deg);
}
```
# --instructions--
使用 `transform` 屬性沿 X 軸翻轉 id 爲 `bottom` 的元素 24 度。
# --hints--
id 爲 `bottom` 的元素應該沿着 X 軸翻轉 24 度。
```js
assert(code.match(/#bottom\s*?{\s*?.*?\s*?transform:\s*?skewX\(24deg\);/g));
```
# --seed--
## --seed-contents--
```html
<style>
div {
width: 70%;
height: 100px;
margin: 50px auto;
}
#top {
background-color: red;
}
#bottom {
background-color: blue;
}
</style>
<div id="top"></div>
<div id="bottom"></div>
```
# --solutions--
```html
<style>
div {
width: 70%;
height: 100px;
margin: 50px auto;
}
#top {
background-color: red;
}
#bottom {
background-color: blue;
transform: skewX(24deg);
}
</style>
<div id="top"></div>
<div id="bottom"></div>
```

View File

@ -0,0 +1,71 @@
---
id: 587d78a6367417b2b2512adc
title: 使用 CSS Transform skex 屬性沿Y軸傾斜元素
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MZ2uB'
forumTopicId: 301075
dashedName: use-the-css-transform-property-skewy-to-skew-an-element-along-the-y-axis
---
# --description--
`skewX` 函數使指定元素沿 X 軸翻轉指定的角度,想必你已經猜到了,`skewY` 屬性使指定元素沿 Y 軸(垂直方向)翻轉指定角度。
# --instructions--
使用 `transform` 屬性沿 Y 軸翻轉 id 爲 `top` 的元素 -10 度。
# --hints--
id 爲 `top` 的元素應該沿着 Y 軸翻轉 -10 度。
```js
assert(code.match(/#top\s*?{\s*?.*?\s*?transform:\s*?skewY\(-10deg\);/g));
```
# --seed--
## --seed-contents--
```html
<style>
div {
width: 70%;
height: 100px;
margin: 50px auto;
}
#top {
background-color: red;
}
#bottom {
background-color: blue;
transform: skewX(24deg);
}
</style>
<div id="top"></div>
<div id="bottom"></div>
```
# --solutions--
```html
<style>
div {
width: 70%;
height: 100px;
margin: 50px auto;
}
#top {
background-color: red;
transform: skewY(-10deg);
}
#bottom {
background-color: blue;
transform: skewX(24deg);
}
</style>
<div id="top"></div>
<div id="bottom"></div>
```

View File

@ -0,0 +1,95 @@
---
id: 587d78a5367417b2b2512ad9
title: 使用 CSS Transform scale 屬性可以更改元素的大小
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MZVSg'
forumTopicId: 301076
dashedName: use-the-css-transform-scale-property-to-change-the-size-of-an-element
---
# --description--
CSS 屬性 `transform` 裏面的 `scale()` 函數可以用來改變元素的顯示比例。 下面的例子把頁面的段落元素放大到了原來的 2 倍:
```css
p {
transform: scale(2);
}
```
# --instructions--
把 id 爲 `ball2` 的元素放大到原始大小的 1.5 倍。
# --hints--
`#ball2``transform` 屬性應該爲原始大小的 1.5 倍。
```js
assert(
code.match(
/#ball2\s*?{\s*?left:\s*?65%;\s*?transform:\s*?scale\(1\.5\);\s*?}|#ball2\s*?{\s*?transform:\s*?scale\(1\.5\);\s*?left:\s*?65%;\s*?}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
.ball {
width: 40px;
height: 40px;
margin: 50 auto;
position: fixed;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
border-radius: 50%;
}
#ball1 {
left: 20%;
}
#ball2 {
left: 65%;
}
</style>
<div class="ball" id= "ball1"></div>
<div class="ball" id= "ball2"></div>
```
# --solutions--
```html
<style>
.ball {
width: 40px;
height: 40px;
margin: 50 auto;
position: fixed;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
border-radius: 50%;
}
#ball1 {
left: 20%;
}
#ball2 {
left: 65%;
transform: scale(1.5);
}
</style>
<div class="ball" id= "ball1"></div>
<div class="ball" id= "ball2"></div>
```

View File

@ -0,0 +1,79 @@
---
id: 587d78a5367417b2b2512ada
title: 使用CSS Transform scale 屬性在懸停時縮放元素
challengeType: 0
videoUrl: 'https://scrimba.com/c/cyLPJuM'
forumTopicId: 301077
dashedName: use-the-css-transform-scale-property-to-scale-an-element-on-hover
---
# --description--
`transform` 屬性有很多函數可以調用,可以對元素進行調整大小、移動、旋轉、翻轉等操作。 當使用僞類選取元素的指定狀態(如 `:hover`)時,我們可以通過 `transform` 屬性非常方便地給元素添加交互。
下面是當用戶懸停在段落元素時,段落大小縮放到原始大小 2.1 倍的例子:
```css
p:hover {
transform: scale(2.1);
}
```
**注意:**給 `div` 元素添加 transform 也會影響這個 div 包裹的子元素。
# --instructions--
通過僞類,給 `div``hover` 狀態添加 `transform` 屬性,使 `div` 當鼠標懸停時大小縮放到原始大小的 1.1 倍。
# --hints--
`div` 元素在懸停時大小應該縮放到原始大小的 1.1 倍。
```js
assert(code.match(/div:hover\s*?{\s*?transform:\s*?scale\(1\.1\);/gi));
```
# --seed--
## --seed-contents--
```html
<style>
div {
width: 70%;
height: 100px;
margin: 50px auto;
background: linear-gradient(
53deg,
#ccfffc,
#ffcccf
);
}
</style>
<div></div>
```
# --solutions--
```html
<style>
div {
width: 70%;
height: 100px;
margin: 50px auto;
background: linear-gradient(
53deg,
#ccfffc,
#ffcccf
);
}
div:hover {
transform: scale(1.1);
}
</style>
<div></div>
```

View File

@ -0,0 +1,118 @@
---
id: 587d781a367417b2b2512ab9
title: 使用 em 標籤強調文本
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJRBtp'
forumTopicId: 301078
dashedName: use-the-em-tag-to-italicize-text
---
# --description--
你可以使用 `em` 標籤來強調文本。 由於瀏覽器會自動給元素應用 `font-style: italic;`,所以文本會顯示爲斜體。
# --instructions--
在段落標籤裏面嵌套 `em` 標籤來強調文本。
# --hints--
應添加一個 `em` 標籤。
```js
assert($('em').length == 1);
```
`em` 標籤應包裹 `p` 標籤裏的內容,但不包裹 `p` 標籤本身。
```js
assert($('p').children().length == 1 && $('em').children().length == 2);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,135 @@
---
id: 587d781b367417b2b2512aba
title: 使用 s 標籤給文本添加刪除線
challengeType: 0
videoUrl: ''
forumTopicId: 301079
dashedName: use-the-s-tag-to-strikethrough-text
---
# --description--
你可以用 `s` 標籤來給文字添加刪除線。 刪除線是位於文字水平中央的一條線,它代表着一段文字不再有效。 添加了 `s` 標籤後,瀏覽器會自動給元素添加這段樣式:`text-decoration: line-through;`
# --instructions--
`h4` 標籤裏的 `Google` 文本外添加 `s` 標籤,然後在 s 標籤後面添加單詞 `Alphabet`,單詞不要有刪除線格式。
# --hints--
應添加一個 `s` 標籤。
```js
assert($('s').length == 1);
```
`s` 標籤應該在 `h4` 標籤內的 `Google` 文字外面, 它不應包含單詞 `Alphabet`
```js
assert(
$('h4 > s')
.text()
.match(/Google/gi) &&
!$('h4 > s')
.text()
.match(/Alphabet/gi)
);
```
`h4` 標籤內應有單詞 `Alphabet`,單詞不應有刪除線樣式。
```js
assert(
$('h4')
.html()
.match(/Alphabet/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4><s>Google</s> Alphabet</h4>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,128 @@
---
id: 587d781a367417b2b2512ab7
title: 使用 strong 標籤加粗文本
challengeType: 0
videoUrl: 'https://scrimba.com/c/ceJNBSb'
forumTopicId: 301080
dashedName: use-the-strong-tag-to-make-text-bold
---
# --description--
你可以使用 `strong` 標籤來加粗文字。 粗體文字一般用來吸引讀者注意或用來表示強調。 添加了 `strong` 標籤後,瀏覽器會自動給元素添加這段樣式:`font-weight:bold;`
# --instructions--
`p` 標籤裏的 `Stanford University` 內容文本添加 `strong` 標籤。
# --hints--
應添加一個 `strong` 標籤。
```js
assert($('strong').length == 1);
```
`strong` 標籤應在 `p` 標籤裏。
```js
assert($('p').children('strong').length == 1);
```
`strong` 標籤的文本應爲 `Stanford University`
```js
assert(
$('strong')
.text()
.match(/^Stanford University\.?$/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at <strong>Stanford University</strong>.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,138 @@
---
id: 587d781c367417b2b2512ac0
title: 使用 text-transform 屬性給文本添加大寫效果
challengeType: 0
videoUrl: 'https://scrimba.com/c/cvVZQSP'
forumTopicId: 301081
dashedName: use-the-text-transform-property-to-make-text-uppercase
---
# --description--
CSS 裏的 `text-transform` 屬性可以改變英文字母的大小寫。 使用這個屬性時,我們無需改變 HTML 元素中的文本也可以統一頁面裏英文的顯示。
下面的表格展示了 `text-transform` 的不同值對文字 “Transform me” 的影響:
<table class='table table-striped'><thead><tr><th></th><th>結果</th></tr></thead><tbody><tr><td><code>lowercase</code></td><td>"transform me"</td></tr><tr><td><code>uppercase</code></td><td>"TRANSFORM ME"</td></tr><tr><td><code>capitalize</code></td><td>"Transform Me"</td></tr><tr><td><code>initial</code></td><td>使用默認值</td></tr><tr><td><code>inherit</code></td><td>使用父元素的 <code>text-transform</code> 值。</td></tr><tr><td><code>none</code></td><td><strong>Default:</strong>不改變文字。</td></tr></tbody></table>
# --instructions--
請使用 `text-transform` 屬性把 `h4` 內容文本中的所有字母變成大寫。
# --hints--
`h4` 內容文本中的所有字母均應爲 `uppercase` 大寫 。
```js
assert($('h4').css('text-transform') === 'uppercase');
```
`h4` 內的原文不應改變。
```js
assert($('h4').text() !== $('h4').text().toUpperCase());
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
opacity: 0.7;
}
#thumbnail {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard" id="thumbnail">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
background-color: rgba(45, 45, 45, 0.1);
padding: 10px;
font-size: 27px;
text-transform: uppercase;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
opacity: 0.7;
}
#thumbnail {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard" id="thumbnail">
<div class="cardContent">
<div class="cardText">
<h4>Alphabet</h4>
<hr>
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,120 @@
---
id: 587d781a367417b2b2512ab8
title: 使用 u 標籤給文本添加下劃線
challengeType: 0
videoUrl: 'https://scrimba.com/c/cN6aQCL'
forumTopicId: 301082
dashedName: use-the-u-tag-to-underline-text
---
# --description--
你可以使用 `u` 標籤來給文字添加下劃線。 下劃線通常用來表示重要內容或需要記憶的內容。 添加了 `u` 標籤後,瀏覽器會自動給元素添加這段樣式:`text-decoration: underline;`
# --instructions--
`u` 標籤包裹的文本內容應爲 `Ph.D. students`
**注意:** 如果使用 `u` 標籤添加下劃線,可能混淆文本和鏈接,則應避免使用它。 錨標籤也有默認的下劃線格式。
# --hints--
應添加一個 `u` 標籤。
```js
assert($('u').length === 1);
```
`u` 標籤的文本內容應爲 `Ph.D. students`
```js
assert($('u').text() === 'Ph.D. students');
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at <strong>Stanford University</strong>.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```
# --solutions--
```html
<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>
<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<p>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
```

View File

@ -0,0 +1,115 @@
---
id: bad87fee1348bd9aedf08823
title: 給元素添加負外邊距
challengeType: 0
videoUrl: 'https://scrimba.com/c/cnpyGs3'
forumTopicId: 16166
dashedName: add-a-negative-margin-to-an-element
---
# --description--
元素的 `margin外邊距` 用來控制元素 `border邊框` 與其周圍元素之間的距離大小。
如果你把元素的 `margin` 設置爲負值,元素會變得佔用更多空間。
# --instructions--
請將藍色框的 `margin` 設爲負值,跟紅色框的一樣。
將藍色框的 `margin` 設置爲 `-15px`,它會讓藍色框填滿整個黃色框。
# --hints--
class 爲 `blue-box` 的元素的 `margin` 應設置爲 `-15px`
```js
assert($('.blue-box').css('margin-top') === '-15px');
```
# --seed--
## --seed-contents--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding: 20px;
margin: -15px;
}
.blue-box {
background-color: blue;
color: #fff;
padding: 20px;
margin: 20px;
}
</style>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```
# --solutions--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding: 20px;
margin: -15px;
}
.blue-box {
background-color: blue;
color: #fff;
padding: 20px;
margin: 20px;
margin-top: -15px;
}
</style>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```

View File

@ -0,0 +1,190 @@
---
id: bad87fee1348bd9bedf08813
title: 在元素周圍添加邊框
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MvnHZ'
forumTopicId: 16630
dashedName: add-borders-around-your-elements
---
# --description--
CSS 邊框具有 `style``color``width` 屬性。
假如我們要將一個 HTML 元素邊框設置爲 5px 的紅色實線邊框,我們可以這樣做:
```html
<style>
.thin-red-border {
border-color: red;
border-width: 5px;
border-style: solid;
}
</style>
```
# --instructions--
創建一個名爲 `thick-green-border` 的 class 該 class 應在 HTML 元素周圍添加一個 10px 的綠色實線邊框。 將這個 class 應用於你的貓圖。
記得在一個元素上可以同時應用多個 `class`,使用空格來分隔不同 class 即可, 例如:
```html
<img class="class1 class2">
```
# --hints--
`img` 元素的 class 應包含 `smaller-image`
```js
assert($('img').hasClass('smaller-image'));
```
`img` 元素應包含 `thick-green-border` class。
```js
assert($('img').hasClass('thick-green-border'));
```
圖片邊框寬度應設置爲 `10px`
```js
assert(
$('img').hasClass('thick-green-border') &&
parseInt($('img').css('border-top-width'), 10) >= 8 &&
parseInt($('img').css('border-top-width'), 10) <= 12
);
```
圖片邊框樣式應爲 `solid` 實線。
```js
assert($('img').css('border-right-style') === 'solid');
```
`img` 元素的邊框顏色應爲綠色。
```js
assert($('img').css('border-left-color') === 'rgb(0, 128, 0)');
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.smaller-image {
width: 100px;
}
.thick-green-border {
border-width: 10px;
border-color: green;
border-style: solid;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,136 @@
---
id: bad87fee1248bd9aedf08824
title: 給元素的每一側添加不同的外邊距
challengeType: 0
videoUrl: 'https://scrimba.com/c/cg4RWh4'
forumTopicId: 16633
dashedName: add-different-margins-to-each-side-of-an-element
---
# --description--
有時候,你會想給一個元素每個方向的 `margin` 都設置成一個特定的值。
CSS 允許你使用 `margin-top``margin-right``margin-bottom``margin-left` 屬性來設置四個不同方向的 `margin` 值。
# --instructions--
請將藍色框的頂部和左側 `margin` 屬性值設置爲 `40px`,將底部和右側的屬性值設置爲 `20px`
# --hints--
class 爲 `blue-box` 的元素的上外邊距屬性值 `margin` 應爲 `40px`
```js
assert($('.blue-box').css('margin-top') === '40px');
```
class 爲 `blue-box` 的元素的右外邊距屬性值 `margin` 應爲 `20px`
```js
assert($('.blue-box').css('margin-right') === '20px');
```
class 爲 `blue-box` 的元素的下外邊距屬性值 `margin` 應爲 `20px`
```js
assert($('.blue-box').css('margin-bottom') === '20px');
```
class 爲 `blue-box` 的元素的左外邊距屬性值 `margin` 應爲 `40px`
```js
assert($('.blue-box').css('margin-left') === '40px');
```
# --seed--
## --seed-contents--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
margin-top: 40px;
margin-right: 20px;
margin-bottom: 20px;
margin-left: 40px;
}
.blue-box {
background-color: blue;
color: #fff;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```
# --solutions--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
margin-top: 40px;
margin-right: 20px;
margin-bottom: 20px;
margin-left: 40px;
}
.blue-box {
background-color: blue;
color: #fff;
margin-top: 40px;
margin-right: 20px;
margin-bottom: 20px;
margin-left: 40px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```

View File

@ -0,0 +1,136 @@
---
id: bad87fee1348bd9aedf08824
title: 給元素的每一側添加不同的內邊距
challengeType: 0
videoUrl: 'https://scrimba.com/c/cB7mwUw'
forumTopicId: 16634
dashedName: add-different-padding-to-each-side-of-an-element
---
# --description--
有時候,你會想給一個元素每個方向的 `padding` 都設置一個特定的值
CSS 允許你使用 `padding-top``padding-right``padding-bottom``padding-left` 屬性來設置四個不同方向的 `padding` 值。
# --instructions--
請將藍色框的頂部和左側 `padding` 屬性值設置爲 `40px`;將底部和右側的屬性值設置爲 `20px`
# --hints--
class 爲 `blue-box` 的元素的上內邊距屬性值 `padding` 應爲 `40px`
```js
assert($('.blue-box').css('padding-top') === '40px');
```
class 爲 `blue-box` 的元素的右內邊距屬性值 `padding` 應爲 `20px`
```js
assert($('.blue-box').css('padding-right') === '20px');
```
class 爲 `blue-box` 的元素的下內邊距屬性值 `padding` 應爲 `20px`
```js
assert($('.blue-box').css('padding-bottom') === '20px');
```
class 爲 `blue-box` 的元素的左內邊距屬性值 `padding` 應爲 `40px`
```js
assert($('.blue-box').css('padding-left') === '40px');
```
# --seed--
## --seed-contents--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding-top: 40px;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 40px;
}
.blue-box {
background-color: blue;
color: #fff;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```
# --solutions--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding-top: 40px;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 40px;
}
.blue-box {
background-color: blue;
color: #fff;
padding-top: 40px;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 40px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```

View File

@ -0,0 +1,164 @@
---
id: bad87fee1348bd9aedf08814
title: 用 border-radius 添加圓角邊框
challengeType: 0
videoUrl: 'https://scrimba.com/c/cbZm2hg'
forumTopicId: 16649
dashedName: add-rounded-corners-with-border-radius
---
# --description--
貓咪圖片的四個角看起來很尖銳, 我們可以使用 `border-radius` 屬性來讓它變得圓潤。
# --instructions--
`border-radius` 的屬性值單位可以是 px像素。 請將貓咪圖片 `border-radius` 的屬性值設置爲 `10px`
**注意:**這個挑戰有多個解決方法。 例如,添加 `border-radius` 屬性到 `.thick-green-border``.smaller-image` 都是可行的。
# --hints--
圖片元素應有 `thick-green-border` class。
```js
assert($('img').hasClass('thick-green-border'));
```
圖片的邊框半徑應爲 `10px`
```js
assert(
$('img').css('border-top-left-radius') === '10px' &&
$('img').css('border-top-right-radius') === '10px' &&
$('img').css('border-bottom-left-radius') === '10px' &&
$('img').css('border-bottom-right-radius') === '10px'
);
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
}
.smaller-image {
width: 100px;
border-radius: 10px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,116 @@
---
id: bad87fee1348bd9aedf08822
title: 調整元素的外邊距
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJarHW'
forumTopicId: 16654
dashedName: adjust-the-margin-of-an-element
---
# --description--
外邊距 `margin` 用來控制元素的邊框與其他元素之間的 `border` 距離。
在這裏,我們可以看到藍色框和紅色框都在黃色框裏。 請注意,紅色框的 `margin` 值要比藍色框的大,因此紅色框看起來比藍色框要小。
如果你增加藍色的 `margin` 值,它也會增加元素邊框到其他周圍元素的距離。
# --instructions--
請將藍色框的 `margin` 值設置成和紅色框的一樣。
# --hints--
class 爲 `blue-box` 的元素的 `margin` 值應爲 `20px`
```js
assert($('.blue-box').css('margin-top') === '20px');
```
# --seed--
## --seed-contents--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding: 20px;
margin: 20px;
}
.blue-box {
background-color: blue;
color: #fff;
padding: 20px;
margin: 10px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```
# --solutions--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding: 20px;
margin: 20px;
}
.blue-box {
background-color: blue;
color: #fff;
padding: 20px;
margin: 20px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```

View File

@ -0,0 +1,118 @@
---
id: bad88fee1348bd9aedf08825
title: 調整元素的內邊距
challengeType: 0
videoUrl: 'https://scrimba.com/c/cED8ZC2'
forumTopicId: 301083
dashedName: adjust-the-padding-of-an-element
---
# --description--
我們暫時把要做的貓咪圖片 App 放在一邊,先來多瞭解一下如何給 HTML 添加樣式。
你可能已經注意到了,所有的 HTML 元素都是以矩形爲基礎。
每個 HTML 元素所佔有的矩形空間由這三個重要的屬性來控制:內邊距 `padding`、外邊距 `margin` 、邊框 `border`
`padding` 用來控制着元素內容與 `border` 之間的空隙大小。
我們可以看到藍色框和紅色框是嵌套在黃色框裏的。 注意紅色框的 `padding` 比藍色框的更多。
如果你增加藍色框的 `padding` 值,其中的文本內容與邊框的距離就也會變大。
# --instructions--
將藍色的框的 `padding` 值設置成與紅色框 `padding` 值一樣。
# --hints--
`blue-box` 這一 class 應將元素的 `padding` 值設置爲 `20px`
```js
assert($('.blue-box').css('padding-top') === '20px');
```
# --seed--
## --seed-contents--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding: 20px;
}
.blue-box {
background-color: blue;
color: #fff;
padding: 10px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```
# --solutions--
```html
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 10px;
}
.red-box {
background-color: crimson;
color: #fff;
padding: 20px;
}
.blue-box {
background-color: blue;
color: #fff;
padding: 20px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box blue-box">padding</h5>
</div>
```

View File

@ -0,0 +1,272 @@
---
id: 5a9d7286424fe3d0e10cad13
title: 給 CSS 變量設置備用值
challengeType: 0
videoUrl: 'https://scrimba.com/c/c6bDNfp'
forumTopicId: 301084
dashedName: attach-a-fallback-value-to-a-css-variable
---
# --description--
使用變量來作爲 CSS 屬性值的時候,可以設置一個備用值來防止由於某些原因導致變量不生效的情況。
**注意:**備用值不是用於增強瀏覽器的兼容性,它也不適用於 IE 瀏覽器。 相反,它是用來讓瀏覽器在找不到你的變量時可以顯示一種顏色。
下面是操作方式:
```css
background: var(--penguin-skin, black);
```
如果你的變量沒有設置,這將會把背景設置爲 `black`。 提示:這對調試代碼也會很有幫助。
# --instructions--
`.penguin-top``.penguin-bottom` 類的變量看起來似乎有點問題。 請爲 class 爲 `penguin-top``penguin-bottom` 的元素的 `background` 屬性設置一個 `black` 的備用色。
# --hints--
class 爲 `penguin-top` 的元素的 `background` 屬性值應有 `black` 作爲備用顏色。
```js
assert(
code.match(
/.penguin-top\s*?{[\s\S]*background\s*?:\s*?var\(\s*?--pengiun-skin\s*?,\s*?black\s*?\)\s*?;[\s\S]*}[\s\S]*.penguin-bottom\s{/gi
)
);
```
class 爲 `penguin-bottom` 的元素的 `background` 屬性值應有 `black` 作爲備用顏色。
```js
assert(
code.match(
/.penguin-bottom\s*?{[\s\S]*background\s*?:\s*?var\(\s*?--pengiun-skin\s*?,\s*?black\s*?\)\s*?;[\s\S]*}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
.penguin {
--penguin-skin: black;
--penguin-belly: gray;
--penguin-beak: yellow;
position: relative;
margin: auto;
display: block;
margin-top: 5%;
width: 300px;
height: 300px;
}
.penguin-top {
top: 10%;
left: 25%;
/* Change code below this line */
background: var(--pengiun-skin);
/* Change code above this line */
width: 50%;
height: 45%;
border-radius: 70% 70% 60% 60%;
}
.penguin-bottom {
top: 40%;
left: 23.5%;
/* Change code below this line */
background: var(--pengiun-skin);
/* Change code above this line */
width: 53%;
height: 45%;
border-radius: 70% 70% 100% 100%;
}
.right-hand {
top: 0%;
left: -5%;
background: var(--penguin-skin, black);
width: 30%;
height: 60%;
border-radius: 30% 30% 120% 30%;
transform: rotate(45deg);
z-index: -1;
}
.left-hand {
top: 0%;
left: 75%;
background: var(--penguin-skin, black);
width: 30%;
height: 60%;
border-radius: 30% 30% 30% 120%;
transform: rotate(-45deg);
z-index: -1;
}
.right-cheek {
top: 15%;
left: 35%;
background: var(--penguin-belly, white);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.left-cheek {
top: 15%;
left: 5%;
background: var(--penguin-belly, white);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.belly {
top: 60%;
left: 2.5%;
background: var(--penguin-belly, white);
width: 95%;
height: 100%;
border-radius: 120% 120% 100% 100%;
}
.right-feet {
top: 85%;
left: 60%;
background: var(--penguin-beak, orange);
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(-80deg);
z-index: -2222;
}
.left-feet {
top: 85%;
left: 25%;
background: var(--penguin-beak, orange);
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(80deg);
z-index: -2222;
}
.right-eye {
top: 45%;
left: 60%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.left-eye {
top: 45%;
left: 25%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.sparkle {
top: 25%;
left: 15%;
background: white;
width: 35%;
height: 35%;
border-radius: 50%;
}
.blush-right {
top: 65%;
left: 15%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.blush-left {
top: 65%;
left: 70%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.beak-top {
top: 60%;
left: 40%;
background: var(--penguin-beak, orange);
width: 20%;
height: 10%;
border-radius: 50%;
}
.beak-bottom {
top: 65%;
left: 42%;
background: var(--penguin-beak, orange);
width: 16%;
height: 10%;
border-radius: 50%;
}
body {
background: #c6faf1;
}
.penguin * {
position: absolute;
}
</style>
<div class="penguin">
<div class="penguin-bottom">
<div class="right-hand"></div>
<div class="left-hand"></div>
<div class="right-feet"></div>
<div class="left-feet"></div>
</div>
<div class="penguin-top">
<div class="right-cheek"></div>
<div class="left-cheek"></div>
<div class="belly"></div>
<div class="right-eye">
<div class="sparkle"></div>
</div>
<div class="left-eye">
<div class="sparkle"></div>
</div>
<div class="blush-right"></div>
<div class="blush-left"></div>
<div class="beak-top"></div>
<div class="beak-bottom"></div>
</div>
</div>
```
# --solutions--
```html
<style>
.penguin-top {
background: var(--pengiun-skin, black);
}
.penguin-bottom {
background: var(--pengiun-skin, black);
}
</style>
```

View File

@ -0,0 +1,254 @@
---
id: 5a9d72a1424fe3d0e10cad15
title: 更改特定區域的變量
challengeType: 0
videoUrl: 'https://scrimba.com/c/cdRwbuW'
forumTopicId: 301085
dashedName: change-a-variable-for-a-specific-area
---
# --description--
當你在 `:root` 裏創建變量時,這些變量的作用域是整個頁面。
如果在元素裏創建相同的變量,會重寫作用於整個頁面的變量的值。
# --instructions--
`penguin` class 裏,請設置 `--penguin-belly` 的值爲 `white`
# --hints--
應在 `penguin` class 裏重定義 `--penguin-belly` 的變量值,新的值應爲 `white`
```js
assert(
code.match(/\.penguin\s*?{[\s\S]*--penguin-belly\s*?:\s*?white\s*?;[\s\S]*}/gi)
);
```
`penguin` class 不應該包含 `background-color` 屬性。
```js
assert(
code.match(/^((?!background-color\s*?:\s*?)[\s\S])*$/g)
);
```
# --seed--
## --seed-contents--
```html
<style>
:root {
--penguin-skin: gray;
--penguin-belly: pink;
--penguin-beak: orange;
}
body {
background: var(--penguin-belly, #c6faf1);
}
.penguin {
/* Only change code below this line */
/* Only change code above this line */
position: relative;
margin: auto;
display: block;
margin-top: 5%;
width: 300px;
height: 300px;
}
.right-cheek {
top: 15%;
left: 35%;
background: var(--penguin-belly, pink);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.left-cheek {
top: 15%;
left: 5%;
background: var(--penguin-belly, pink);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.belly {
top: 60%;
left: 2.5%;
background: var(--penguin-belly, pink);
width: 95%;
height: 100%;
border-radius: 120% 120% 100% 100%;
}
.penguin-top {
top: 10%;
left: 25%;
background: var(--penguin-skin, gray);
width: 50%;
height: 45%;
border-radius: 70% 70% 60% 60%;
}
.penguin-bottom {
top: 40%;
left: 23.5%;
background: var(--penguin-skin, gray);
width: 53%;
height: 45%;
border-radius: 70% 70% 100% 100%;
}
.right-hand {
top: 0%;
left: -5%;
background: var(--penguin-skin, gray);
width: 30%;
height: 60%;
border-radius: 30% 30% 120% 30%;
transform: rotate(45deg);
z-index: -1;
}
.left-hand {
top: 0%;
left: 75%;
background: var(--penguin-skin, gray);
width: 30%;
height: 60%;
border-radius: 30% 30% 30% 120%;
transform: rotate(-45deg);
z-index: -1;
}
.right-feet {
top: 85%;
left: 60%;
background: var(--penguin-beak, orange);
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(-80deg);
z-index: -2222;
}
.left-feet {
top: 85%;
left: 25%;
background: var(--penguin-beak, orange);
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(80deg);
z-index: -2222;
}
.right-eye {
top: 45%;
left: 60%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.left-eye {
top: 45%;
left: 25%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.sparkle {
top: 25%;
left: 15%;
background: white;
width: 35%;
height: 35%;
border-radius: 50%;
}
.blush-right {
top: 65%;
left: 15%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.blush-left {
top: 65%;
left: 70%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.beak-top {
top: 60%;
left: 40%;
background: var(--penguin-beak, orange);
width: 20%;
height: 10%;
border-radius: 50%;
}
.beak-bottom {
top: 65%;
left: 42%;
background: var(--penguin-beak, orange);
width: 16%;
height: 10%;
border-radius: 50%;
}
.penguin * {
position: absolute;
}
</style>
<div class="penguin">
<div class="penguin-bottom">
<div class="right-hand"></div>
<div class="left-hand"></div>
<div class="right-feet"></div>
<div class="left-feet"></div>
</div>
<div class="penguin-top">
<div class="right-cheek"></div>
<div class="left-cheek"></div>
<div class="belly"></div>
<div class="right-eye">
<div class="sparkle"></div>
</div>
<div class="left-eye">
<div class="sparkle"></div>
</div>
<div class="blush-right"></div>
<div class="blush-left"></div>
<div class="beak-top"></div>
<div class="beak-bottom"></div>
</div>
</div>
```
# --solutions--
```html
<style>
.penguin {--penguin-belly: white;}
</style>
```

View File

@ -0,0 +1,122 @@
---
id: bad87fee1348bd9aedf08803
title: 更改文本的顏色
challengeType: 0
videoUrl: 'https://scrimba.com/c/cRkVmSm'
forumTopicId: 16775
dashedName: change-the-color-of-text
---
# --description--
現在讓我們來修改文本的顏色。
我們通過修改 `h2` 元素的 `style` 屬性來改變文本顏色。
我們需要修改 `color` 屬性值。
以下是將 `h2` 元素設置爲藍色的方法:
```html
<h2 style="color: blue;">CatPhotoApp</h2>
```
請注意,需要在內聯 `style` 聲明末尾加上 `;`
# --instructions--
修改 `h2` 的樣式,使它的文本顏色爲紅色。
# --hints--
`h2` 元素應有一個 `style` 聲明。
```js
assert($('h2').attr('style'));
```
`h2` 元素的顏色應設置爲 `red`
```js
assert($('h2')[0].style.color === 'red');
```
`style` 聲明應該以 `;` 結尾。
```js
assert($('h2').attr('style') && $('h2').attr('style').endsWith(';'));
```
# --seed--
## --seed-contents--
```html
<h2>CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<h2 style="color: red;">CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,119 @@
---
id: bad87fee1348bd9aedf08806
title: 更改元素的字體大小
challengeType: 0
videoUrl: 'https://scrimba.com/c/c3bvDc8'
forumTopicId: 16777
dashedName: change-the-font-size-of-an-element
---
# --description--
字體大小由 `font-size` 屬性控制,如下所示:
```css
h1 {
font-size: 30px;
}
```
# --instructions--
在包含 `red-text` 的類選擇器的 `<style>` 聲明區域的裏,創建一個 `p` 元素樣式規則,並設置其 `font-size``16px`
# --hints--
`style` 樣式聲明區域裏,`p` 元素的 `font-size` 的值應爲 `16px`。 請注意,瀏覽器和文本縮放應設置爲 100
```js
assert(code.match(/p\s*{\s*font-size\s*:\s*16\s*px\s*;\s*}/i));
```
# --seed--
## --seed-contents--
```html
<style>
.red-text {
color: red;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<style>
.red-text {
color: red;
}
p {
font-size: 16px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,241 @@
---
id: 5a9d726c424fe3d0e10cad11
title: 創建一個自定義的 CSS 變量
challengeType: 0
videoUrl: 'https://scrimba.com/c/cQd27Hr'
forumTopicId: 301086
dashedName: create-a-custom-css-variable
---
# --description--
爲創建一個 CSS 變量,你只需要在變量名前添加兩個連字符號,併爲其賦值即可,例子如下:
```css
--penguin-skin: gray;
```
這樣就會創建一個 `--penguin-skin` 變量,它的值爲 `gray`。 現在,其他元素可通過該變量來使元素變成灰色。
# --instructions--
`penguin` class 裏面,創建一個 `--penguin-skin` 變量,並將其值設置爲 `gray`
# --hints--
應在 `penguin` class 裏聲明 `--penguin-skin` 變量,且賦值爲 `gray`
```js
assert(
code.match(/\.penguin\s*\{[^{}]*?--penguin-skin\s*:\s*gr[ae]y\s*;[^{}]*?\}/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
.penguin {
/* Only change code below this line */
/* Only change code above this line */
position: relative;
margin: auto;
display: block;
margin-top: 5%;
width: 300px;
height: 300px;
}
.penguin-top {
top: 10%;
left: 25%;
background: black;
width: 50%;
height: 45%;
border-radius: 70% 70% 60% 60%;
}
.penguin-bottom {
top: 40%;
left: 23.5%;
background: black;
width: 53%;
height: 45%;
border-radius: 70% 70% 100% 100%;
}
.right-hand {
top: 0%;
left: -5%;
background: black;
width: 30%;
height: 60%;
border-radius: 30% 30% 120% 30%;
transform: rotate(45deg);
z-index: -1;
}
.left-hand {
top: 0%;
left: 75%;
background: black;
width: 30%;
height: 60%;
border-radius: 30% 30% 30% 120%;
transform: rotate(-45deg);
z-index: -1;
}
.right-cheek {
top: 15%;
left: 35%;
background: white;
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.left-cheek {
top: 15%;
left: 5%;
background: white;
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.belly {
top: 60%;
left: 2.5%;
background: white;
width: 95%;
height: 100%;
border-radius: 120% 120% 100% 100%;
}
.right-feet {
top: 85%;
left: 60%;
background: orange;
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(-80deg);
z-index: -2222;
}
.left-feet {
top: 85%;
left: 25%;
background: orange;
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(80deg);
z-index: -2222;
}
.right-eye {
top: 45%;
left: 60%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.left-eye {
top: 45%;
left: 25%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.sparkle {
top: 25%;
left: 15%;
background: white;
width: 35%;
height: 35%;
border-radius: 50%;
}
.blush-right {
top: 65%;
left: 15%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.blush-left {
top: 65%;
left: 70%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.beak-top {
top: 60%;
left: 40%;
background: orange;
width: 20%;
height: 10%;
border-radius: 50%;
}
.beak-bottom {
top: 65%;
left: 42%;
background: orange;
width: 16%;
height: 10%;
border-radius: 50%;
}
body {
background:#c6faf1;
}
.penguin * {
position: absolute;
}
</style>
<div class="penguin">
<div class="penguin-bottom">
<div class="right-hand"></div>
<div class="left-hand"></div>
<div class="right-feet"></div>
<div class="left-feet"></div>
</div>
<div class="penguin-top">
<div class="right-cheek"></div>
<div class="left-cheek"></div>
<div class="belly"></div>
<div class="right-eye">
<div class="sparkle"></div>
</div>
<div class="left-eye">
<div class="sparkle"></div>
</div>
<div class="blush-right"></div>
<div class="blush-left"></div>
<div class="beak-top"></div>
<div class="beak-bottom"></div>
</div>
</div>
```
# --solutions--
```html
<style>.penguin {--penguin-skin: gray;}</style>
```

View File

@ -0,0 +1,176 @@
---
id: bad87fed1348bd9aede07836
title: 給 div 元素添加背景色
challengeType: 0
videoUrl: 'https://scrimba.com/c/cdRKMCk'
forumTopicId: 18190
dashedName: give-a-background-color-to-a-div-element
---
# --description--
`background-color` 屬性可以設置元素的背景顏色。
如果想將一個元素的背景顏色改爲 `green`,可以在 `style` 裏面這樣寫:
```css
.green-background {
background-color: green;
}
```
# --instructions--
創建一個叫作 `silver-background` 的 class並設置 `background-color``silver`。 之後,將這個 class 添加到 `div` 元素上。
# --hints--
`div` 元素應有 `silver-background` class。
```js
assert($('div').hasClass('silver-background'));
```
`div` 元素背景顏色應設置爲銀色。
```js
assert($('div').css('background-color') === 'rgb(192, 192, 192)');
```
class 名 `silver-background` 應該定義在 `style` 元素內;`background-color` 的屬性值應爲 `silver`
```js
assert(code.match(/\.silver-background\s*{\s*background-color:\s*silver;\s*}/));
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
.silver-background {
background-color: silver;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div class="silver-background">
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,175 @@
---
id: bad87fee1348bd9aedf08807
title: 引入谷歌字體
challengeType: 0
videoUrl: 'https://scrimba.com/c/cM9MRsJ'
forumTopicId: 18200
dashedName: import-a-google-font
---
# --description--
在我們的網站上,除了使用系統提供的默認字體以外,我們也可以使用自定義字體。 網絡上有很多字體庫。 在這個例子中,我們將使用 Google 字體庫。
[Google 字體庫](https://fonts.google.com/)是一個免費的 Web 字體庫,我們只需要在 CSS 裏設置字體的 URL 即可使用。
接下來,我們就要引入和使用 Google Fonts注意如果 Google 在你的地區被限制訪問,你可以選擇跳過這個挑戰)。
要引入 Google Font你需要從 Google Fonts 上覆制字體的 URL並粘貼到你的 HTML 裏面。 在這個挑戰中,我們需要引入 `Lobster` 字體。 因此,請複製以下代碼段,並粘貼到代碼編輯器頂部,即放到 `style` 標籤之前。
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
```
現在可以在 CSS 中使用 `Lobster` 字體,並像下面一樣使用 `Lobster` 作爲 FAMILY_NAME
```css
font-family: FAMILY_NAME, GENERIC_NAME;
```
GENERIC_NAME 是可選的,它用來指明在其他字體不可用時的後備字體。 我們會在下一個挑戰中詳細說明。
字體名區分大小寫,並且如果字體名含有空格,則在聲明時需要用引號包起來。 例如,使用 `"Open Sans"` 字體需要添加引號,而 `Lobster` 則不需要。
# --instructions--
給你的網頁導入 `Lobster` 字體。 然後使用元素選擇器將 `h2` 元素的 `font-family` 設置爲 `Lobster`
# --hints--
應引入 `Lobster` 字體。
```js
assert(new RegExp('googleapis', 'gi').test(code));
```
`h2` 元素應使用 `Lobster` 字體。
```js
assert(
$('h2')
.css('font-family')
.match(/lobster/i)
);
```
應使用元素選擇器(`h2`)來改變字體樣式。
```js
assert(
/\s*[^\.]h2\s*\{\s*font-family\s*:\s*('|"|)Lobster\1\s*(,\s*('|"|)[a-z -]+\3\s*)?(;\s*\}|\})/gi.test(
code
)
);
```
`p` 元素應保持使用 `monospace` 字體。
```js
assert(
$('p')
.css('font-family')
.match(/monospace/i)
);
```
# --seed--
## --seed-contents--
```html
<style>
.red-text {
color: red;
}
p {
font-size: 16px;
font-family: monospace;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
p {
font-size: 16px;
font-family: monospace;
}
h2 {
font-family: Lobster;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,70 @@
---
id: 5b7d72c338cd7e35b63f3e14
title: 通過瀏覽器降級提高兼容性
challengeType: 0
videoUrl: ''
forumTopicId: 301087
dashedName: improve-compatibility-with-browser-fallbacks
---
# --description--
使用 CSS 時可能會遇到瀏覽器兼容性問題。 提供瀏覽器降級方案來避免潛在的問題會顯得很重要。
當瀏覽器解析頁面的 CSS 時,會自動忽視不能識別或者不支持的屬性。 舉個例子,如果使用 CSS 變量來指定站點的背景色IE 瀏覽器由於不支持 CSS 變量而會忽略背景色。 此時,瀏覽器會嘗試使用其它值。 但如果沒有找到其它值,則會使用默認值,也就是沒有背景色。
這意味着如果想提供瀏覽器降級方案,在聲明之前提供另一個更寬泛的值即可。 這樣老舊的瀏覽器會降級使用這個方案,新的瀏覽器會在後面的聲明裏覆蓋降級方案。
# --instructions--
我們使用了 CSS 變量來定義 `.red-box` 的背景色。 現在,我們通過在現有的聲明之前添加另一個 `background` 聲明,並將它的值設置爲 `red`,來提升瀏覽器的兼容性。
# --hints--
`.red-box` 規則應在現有的 `background` 聲明之前有一個 `background` 的備用屬性,其值爲 `red`
```js
assert(
code
.replace(/\s/g, '')
.match(
/\.red-box{background:(red|#ff0000|#f00|rgb\(255,0,0\)|rgb\(100%,0%,0%\)|hsl\(0,100%,50%\));background:var\(--red-color\);height:200px;width:200px;}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
:root {
--red-color: red;
}
.red-box {
background: var(--red-color);
height: 200px;
width:200px;
}
</style>
<div class="red-box"></div>
```
# --solutions--
```html
<style>
:root {
--red-color: red;
}
.red-box {
background: red;
background: var(--red-color);
height: 200px;
width:200px;
}
</style>
<div class="red-box"></div>
```

View File

@ -0,0 +1,244 @@
---
id: 5a9d7295424fe3d0e10cad14
title: 繼承 CSS 變量
challengeType: 0
videoUrl: 'https://scrimba.com/c/cyLZZhZ'
forumTopicId: 301088
dashedName: inherit-css-variables
---
# --description--
當創建一個變量時,變量會在創建變量的選擇器裏可用。 同時,在這個選擇器的後代選擇器裏也是可用的。 這是因爲 CSS 變量是可繼承的,和普通的屬性一樣。
CSS 變量經常會定義在 <dfn>:root</dfn> 元素內,這樣就可被所有選擇器繼承。
`:root` 是一個<dfn>僞類</dfn>選擇器,它是一個能夠匹配文檔根元素的選擇器,通常指的是 `html` 元素。 我們在 `:root` 裏創建變量在全局都可用,即在任何選擇器裏都生效。
# --instructions--
`:root` 選擇器裏定義變量 `--penguin-belly` 並設置它的屬性值爲 `pink`。 此時,你會發現變量被繼承,所有使用該變量的子元素都會有粉色背景。
# --hints--
應在 `:root` 裏聲明 `--penguin-belly` 變量並賦值 `pink`
```js
assert(
code.match(/:root\s*?{[\s\S]*--penguin-belly\s*?:\s*?pink\s*?;[\s\S]*}/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
:root {
/* Only change code below this line */
/* Only change code above this line */
}
body {
background: var(--penguin-belly, #c6faf1);
}
.penguin {
--penguin-skin: gray;
--penguin-beak: orange;
position: relative;
margin: auto;
display: block;
margin-top: 5%;
width: 300px;
height: 300px;
}
.right-cheek {
top: 15%;
left: 35%;
background: var(--penguin-belly, white);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.left-cheek {
top: 15%;
left: 5%;
background: var(--penguin-belly, white);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
.belly {
top: 60%;
left: 2.5%;
background: var(--penguin-belly, white);
width: 95%;
height: 100%;
border-radius: 120% 120% 100% 100%;
}
.penguin-top {
top: 10%;
left: 25%;
background: var(--penguin-skin, gray);
width: 50%;
height: 45%;
border-radius: 70% 70% 60% 60%;
}
.penguin-bottom {
top: 40%;
left: 23.5%;
background: var(--penguin-skin, gray);
width: 53%;
height: 45%;
border-radius: 70% 70% 100% 100%;
}
.right-hand {
top: 0%;
left: -5%;
background: var(--penguin-skin, gray);
width: 30%;
height: 60%;
border-radius: 30% 30% 120% 30%;
transform: rotate(45deg);
z-index: -1;
}
.left-hand {
top: 0%;
left: 75%;
background: var(--penguin-skin, gray);
width: 30%;
height: 60%;
border-radius: 30% 30% 30% 120%;
transform: rotate(-45deg);
z-index: -1;
}
.right-feet {
top: 85%;
left: 60%;
background: var(--penguin-beak, orange);
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(-80deg);
z-index: -2222;
}
.left-feet {
top: 85%;
left: 25%;
background: var(--penguin-beak, orange);
width: 15%;
height: 30%;
border-radius: 50% 50% 50% 50%;
transform: rotate(80deg);
z-index: -2222;
}
.right-eye {
top: 45%;
left: 60%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.left-eye {
top: 45%;
left: 25%;
background: black;
width: 15%;
height: 17%;
border-radius: 50%;
}
.sparkle {
top: 25%;
left: 15%;
background: white;
width: 35%;
height: 35%;
border-radius: 50%;
}
.blush-right {
top: 65%;
left: 15%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.blush-left {
top: 65%;
left: 70%;
background: pink;
width: 15%;
height: 10%;
border-radius: 50%;
}
.beak-top {
top: 60%;
left: 40%;
background: var(--penguin-beak, orange);
width: 20%;
height: 10%;
border-radius: 50%;
}
.beak-bottom {
top: 65%;
left: 42%;
background: var(--penguin-beak, orange);
width: 16%;
height: 10%;
border-radius: 50%;
}
.penguin * {
position: absolute;
}
</style>
<div class="penguin">
<div class="penguin-bottom">
<div class="right-hand"></div>
<div class="left-hand"></div>
<div class="right-feet"></div>
<div class="left-feet"></div>
</div>
<div class="penguin-top">
<div class="right-cheek"></div>
<div class="left-cheek"></div>
<div class="belly"></div>
<div class="right-eye">
<div class="sparkle"></div>
</div>
<div class="left-eye">
<div class="sparkle"></div>
</div>
<div class="blush-right"></div>
<div class="blush-left"></div>
<div class="beak-top"></div>
<div class="beak-bottom"></div>
</div>
</div>
```
# --solutions--
```html
<style>:root {--penguin-belly: pink;}</style>
```

View File

@ -0,0 +1,111 @@
---
id: bad87fee1348bd9aedf08746
title: 從 body 元素繼承樣式
challengeType: 0
videoUrl: 'https://scrimba.com/c/c9bmdtR'
forumTopicId: 18204
dashedName: inherit-styles-from-the-body-element
---
# --description--
我們已經證明每一個 HTML 頁面都含有 `body` 元素,我們也可以在 `body` 元素上使用 CSS 樣式。
設置 `body` 元素樣式的方法跟設置其他 HTML 元素樣式的方式一樣,並且其他元素也會繼承 `body` 中所設置的樣式。
# --instructions--
首先,創建一個內容文本爲 `Hello World``h1` 元素。
接着,在 `body` 的 CSS 規則裏面添加 `color: green;`,這會將頁面內所有字體的顏色都設置爲 `green`
最後,在 `body` 的 CSS 規則裏面添加 `font-family: monospace;`,這會將 `body` 內所有元素的字體都設置爲 `monospace`
# --hints--
應創建一個 `h1` 元素。
```js
assert($('h1').length > 0);
```
`h1` 元素的內容文本應爲 `Hello World`
```js
assert(
$('h1').length > 0 &&
$('h1')
.text()
.match(/hello world/i)
);
```
確保 `h1` 元素具有結束標籤。
```js
assert(
code.match(/<\/h1>/g) &&
code.match(/<h1/g) &&
code.match(/<\/h1>/g).length === code.match(/<h1/g).length
);
```
`body` 元素的 `color` 屬性值應爲 `green`
```js
assert($('body').css('color') === 'rgb(0, 128, 0)');
```
`body` 元素的 `font-family` 屬性值應爲 `monospace`
```js
assert(
$('body')
.css('font-family')
.match(/monospace/i)
);
```
`h1` 元素應該繼承 `body``monospace` 字體屬性。
```js
assert(
$('h1').length > 0 &&
$('h1')
.css('font-family')
.match(/monospace/i)
);
```
`h1` 元素的字體顏色應繼承 `body` 元素所設置的綠色。
```js
assert($('h1').length > 0 && $('h1').css('color') === 'rgb(0, 128, 0)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: black;
}
</style>
```
# --solutions--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
</style>
<h1>Hello World!</h1>
```

View File

@ -0,0 +1,159 @@
---
id: bad87fee1348bd9aedf08815
title: 用 border-radius 製作圓形圖片
challengeType: 0
videoUrl: 'https://scrimba.com/c/c2MvrcB'
forumTopicId: 18229
dashedName: make-circular-images-with-a-border-radius
---
# --description--
除像素外,你也可以使用百分比來指定 `border-radius` 的值。
# --instructions--
`border-radius` 的屬性值設置爲 `50%`
# --hints--
圖片的邊框圓角應設置爲 `50%`,這樣圖片就會是圓形的。
```js
assert(parseInt($('img').css('border-top-left-radius')) > 48);
```
`border-radius` 的值應爲 `50%`
```js
assert(code.match(/50%/g));
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 10px;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 10px;
}
.smaller-image {
width: 100px;
border-radius: 50%;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,114 @@
---
id: bad87fee1348bd9aedf07756
title: Important 的優先級最高
challengeType: 0
videoUrl: 'https://scrimba.com/c/cm24rcp'
forumTopicId: 18249
dashedName: override-all-other-styles-by-using-important
---
# --description--
耶! 我們剛剛又證明了行內樣式會覆蓋 `style` 標籤裏面所有的 CSS 聲明。
不過, 還有一種方式可以覆蓋重新 CSS 樣式。 這是所有方法裏面最強大的一個。 在此之前,我們要考慮清楚,爲什麼我們要覆蓋 CSS 樣式。
很多時候,你會使用 CSS 庫, CSS 庫中的樣式會意外覆蓋你的 CSS 樣式。 如果想保證你的 CSS 樣式不受影響,你可以使用 `!important`
讓我們回到 `pink-text` 類聲明。 `pink-text` 類的顏色樣式已被之後的 class 聲明、id 聲明以及行內樣式所覆蓋。
# --instructions--
給粉紅文本元素的顏色聲明添加關鍵詞 `!important`,以確保 `h1` 元素爲粉紅色。
如下所示:
```css
color: red !important;
```
# --hints--
`h1` 元素應包含 `pink-text` class。
```js
assert($('h1').hasClass('pink-text'));
```
`h1` 元素應包含 `blue-text` class。
```js
assert($('h1').hasClass('blue-text'));
```
`h1` 元素應有 `id` 值爲 `orange-text`
```js
assert($('h1').attr('id') === 'orange-text');
```
`h1` 元素應有一個內聯樣式 `color: white`
```js
assert(code.match(/<h1.*style/gi) && code.match(/<h1.*style.*color\s*?:/gi));
```
`pink-text` class 應有 `!important` 關鍵詞 ,以覆蓋其他聲明。
```js
assert(
code.match(/\.pink-text\s*?\{[\s\S]*?color:.*pink.*!important\s*;?[^\.]*\}/g)
);
```
`h1` 元素應爲粉紅色。
```js
assert($('h1').css('color') === 'rgb(255, 192, 203)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
#orange-text {
color: orange;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
</style>
<h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
```
# --solutions--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
#orange-text {
color: orange;
}
.pink-text {
color: pink !important;
}
.blue-text {
color: blue;
}
</style>
<h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
```

View File

@ -0,0 +1,123 @@
---
id: bad87fee1348bd8aedf06756
title: ID 選擇器優先級高於 Class 選擇器
challengeType: 0
videoUrl: 'https://scrimba.com/c/cRkpDhB'
forumTopicId: 18251
dashedName: override-class-declarations-by-styling-id-attributes
---
# --description--
我們剛剛證明了瀏覽器讀取 CSS 是由上到下的。 這就意味着,如果發生衝突,瀏覽器將會應用最後聲明的樣式。 注意,如果我們在 `h1` 元素的類中,將 `blue-text` 放置在 `pink-text` 之前,它仍然會檢查聲明順序,而不是使用順序!
但我們還沒有完成。 其實還有其他方法可以覆蓋 CSS 樣式。 你還記得 id 屬性嗎?
我們來通過給 `h1` 元素添加 id 屬性,覆蓋 `pink-text``blue-text` 類,使 `h1` 元素變成橘色。
# --instructions--
`h1` 元素添加 `id` 屬性,屬性值爲 `orange-text`。 設置方式如下:
```html
<h1 id="orange-text">
```
`h1` 元素需繼續保留 `blue-text``pink-text` 這兩個 class。
`style` 元素中創建名爲 `orange-text` 的 id 選擇器。 例子如下:
```css
#brown-text {
color: brown;
}
```
**注意:** 無論在 `pink-text` class 之前或者之後聲明,`id` 選擇器的優先級總是高於 class 選擇器。
# --hints--
`h1` 元素的應有一個 class 爲 `pink-text`
```js
assert($('h1').hasClass('pink-text'));
```
`h1` 元素應包含 `blue-text` class。
```js
assert($('h1').hasClass('blue-text'));
```
`h1` 元素的 id 應爲 `orange-text`
```js
assert($('h1').attr('id') === 'orange-text');
```
應只有一個 `h1` 元素。
```js
assert($('h1').length === 1);
```
應存在名爲 `orange-text` 的 id 選擇器。
```js
assert(code.match(/#orange-text\s*{/gi));
```
不要在 `h1` 元素裏面使用 `style` 屬性。
```js
assert(!code.match(/<h1.*style.*>/gi));
```
`h1` 元素的字體顏色應爲橘色。
```js
assert($('h1').css('color') === 'rgb(255, 165, 0)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
</style>
<h1 class="pink-text blue-text">Hello World!</h1>
```
# --solutions--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
#orange-text {
color: orange;
}
</style>
<h1 id="orange-text" class="pink-text blue-text">Hello World!</h1>
```

View File

@ -0,0 +1,102 @@
---
id: bad87fee1348bd9aedf06756
title: 內聯樣式的優先級高於 ID 選擇器
challengeType: 0
videoUrl: 'https://scrimba.com/c/cGJDRha'
forumTopicId: 18252
dashedName: override-class-declarations-with-inline-styles
---
# --description--
我們剛剛證明了id 選擇器無論在 `style` 標籤的任何位置聲明,都會覆蓋 class 聲明的樣式。
其實還有其他方法可以覆蓋 CSS 樣式。 你還記得行內樣式嗎?
# --instructions--
使用行內樣式嘗試讓 `h1` 的字體顏色變白。 記住,內聯樣式看起來是像這樣:
```html
<h1 style="color: green;">
```
`h1` 元素應繼續保留 `blue-text``pink-text` 這兩個 class。
# --hints--
`h1` 元素應包含 `pink-text` class。
```js
assert($('h1').hasClass('pink-text'));
```
`h1` 元素應包含 `blue-text` class。
```js
assert($('h1').hasClass('blue-text'));
```
`h1` 的 id 屬性值應爲 `orange-text`
```js
assert($('h1').attr('id') === 'orange-text');
```
`h1` 元素應含有行內樣式。
```js
assert(document.querySelector('h1[style]'));
```
`h1` 元素的字體顏色應該爲白色。
```js
assert($('h1').css('color') === 'rgb(255, 255, 255)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
#orange-text {
color: orange;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
</style>
<h1 id="orange-text" class="pink-text blue-text">Hello World!</h1>
```
# --solutions--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
#orange-text {
color: orange;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
</style>
<h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
```

View File

@ -0,0 +1,94 @@
---
id: bad87fee1348bd9aedf04756
title: Class 選擇器的優先級高於繼承樣式
challengeType: 0
videoUrl: 'https://scrimba.com/c/cGJDQug'
forumTopicId: 18253
dashedName: override-styles-in-subsequent-css
---
# --description--
我們的 `pink-text` class 覆蓋了 `body` 元素的 CSS 樣式!
我們剛剛證明了 class 會覆蓋 `body` 的 CSS 樣式。 那麼下一個問題是,要怎麼樣才能覆蓋 `pink-text` class 中所定義的樣式?
# --instructions--
創建一個 `blue-text` class將元素的顏色設置爲藍色。 將它放在 `pink-text` class 下面。
創建一個字體顏色爲 `blue``blue-text` class並確保它在 `pink-text` 下方聲明。
HTML 同時應用多個 class 屬性需以空格來間隔,例子如下:
```html
class="class1 class2"
```
**注意:**HTML 元素裏應用的 class 的先後順序無關緊要。
但是,在 `<style>` 標籤裏面聲明的 `class` 順序十分重要,之後的聲明會覆蓋之前的聲明。 第二個聲明的優先級始終高於第一個聲明。 由於 `.blue-text` 是在後面聲明的,所以它的樣式會覆蓋 `.pink-text` 裏的樣式。
# --hints--
`h1` 元素應包含 `pink-text` class。
```js
assert($('h1').hasClass('pink-text'));
```
`h1` 元素應包含 `blue-text` class。
```js
assert($('h1').hasClass('blue-text'));
```
`blue-text``pink-text` 需同時應用於 `h1` 元素上。
```js
assert($('.pink-text').hasClass('blue-text'));
```
`h1` 元素的顏色應爲藍色。
```js
assert($('h1').css('color') === 'rgb(0, 0, 255)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
</style>
<h1 class="pink-text">Hello World!</h1>
```
# --solutions--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
</style>
<h1 class="pink-text blue-text">Hello World!</h1>
```

View File

@ -0,0 +1,73 @@
---
id: bad87fee1348bd9aedf08756
title: 樣式中的優先級
challengeType: 0
videoUrl: 'https://scrimba.com/c/cZ8wnHv'
forumTopicId: 18258
dashedName: prioritize-one-style-over-another
---
# --description--
有時候HTML 元素的樣式會跟其他樣式發生衝突。
就像 `h1` 元素不能同時設置綠色和粉色兩種顏色。
讓我們嘗試創建一個字體顏色爲粉色的 class並應用於其中一個元素中。 猜一猜,它會 *覆蓋* `body` 元素的 `color: green;` CSS 規則嗎?
# --instructions--
創建一個能將元素的字體顏色改爲粉色的 class並命名爲 `pink-text`
`h1` 元素添加 `pink-text` class。
# --hints--
`h1` 元素應含有 `pink-text` class。
```js
assert($('h1').hasClass('pink-text'));
```
`<style>` 標籤應含有一個可以改變 `color``pink-text` class。
```js
assert(code.match(/\.pink-text\s*\{\s*color\s*:\s*.+\s*;\s*\}/g));
```
`h1` 元素的字體顏色應爲粉色。
```js
assert($('h1').css('color') === 'rgb(255, 192, 203)');
```
# --seed--
## --seed-contents--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
</style>
<h1>Hello World!</h1>
```
# --solutions--
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
</style>
<h1 class="pink-text">Hello World!</h1>
```

View File

@ -0,0 +1,132 @@
---
id: bad87fee1348bd9aede08807
title: 設置元素的字體族名
challengeType: 0
videoUrl: 'https://scrimba.com/c/c3bvpCg'
forumTopicId: 18278
dashedName: set-the-font-family-of-an-element
---
# --description--
通過 `font-family` 屬性,我們可以設置元素裏的字體族名。
如果你想將 `h2` 元素的字體設置爲 `sans-serif`,可以這樣寫:
```css
h2 {
font-family: sans-serif;
}
```
# --instructions--
請將 `p` 元素的字體設置爲 `monospace`
# --hints--
`p` 元素應使用 `monospace` 作爲字體。
```js
assert(
$('p')
.not('.red-text')
.css('font-family')
.match(/monospace/i)
);
```
# --seed--
## --seed-contents--
```html
<style>
.red-text {
color: red;
}
p {
font-size: 16px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<style>
.red-text {
color: red;
}
p {
font-size: 16px;
font-family: monospace;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,170 @@
---
id: bad87eee1348bd9aede07836
title: 設置元素的 id
challengeType: 0
videoUrl: 'https://scrimba.com/c/cN6MEc2'
forumTopicId: 18279
dashedName: set-the-id-of-an-element
---
# --description--
除了 class 屬性,每一個 HTML 元素都有一個 `id` 屬性。
使用 `id` 有幾個好處:你可以通過 `id` 選擇器來改變單個元素的樣式。在稍後的課程中,你還會了解到如何在 JavaScript 裏面用它來選擇和操作元素。
根據規範,`id` 屬性應是唯一的。 儘管瀏覽器並非必須執行這條規範,但這是廣泛認可的最佳實踐。 因此,請不要給多個元素設置相同的 `id`
設置 `h2` 元素的 id 爲 `cat-photo-app` 的代碼如下:
```html
<h2 id="cat-photo-app">
```
# --instructions--
設置`form`元素的 id 爲`cat-photo-form`
# --hints--
`form` 元素的 id 應爲 `cat-photo-form`
```js
assert($('form').attr('id') === 'cat-photo-form');
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
.silver-background {
background-color: silver;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div class="silver-background">
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
.silver-background {
background-color: silver;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div class="silver-background">
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo" id="cat-photo-form">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

View File

@ -0,0 +1,156 @@
---
id: bad87fee1348bd9acdf08812
title: 調整圖片的大小
challengeType: 0
videoUrl: 'https://scrimba.com/c/cM9MmCP'
forumTopicId: 18282
dashedName: size-your-images
---
# --description--
CSS 的 `width` 屬性可以控制元素的寬度。 和設置文本字號一樣,我們會以 `px`(像素)爲單位來設置圖片的寬度。
例如,如果你想創建一個叫 `larger-image` 的 CSS class來控制 HTML 元素的寬度爲 500px就可以這樣寫
```html
<style>
.larger-image {
width: 500px;
}
</style>
```
# --instructions--
創建一個叫 `smaller-image` 的 CSS class並用它來設置圖片寬度爲 100px。
# --hints--
`img` 元素應包含 `smaller-image` class。
```js
assert(
$("img[src='https://bit.ly/fcc-relaxing-cat']").attr('class') ===
'smaller-image'
);
```
圖片寬度應爲 100px。
```js
assert(
$('img').width() < 200 &&
code.match(/\.smaller-image\s*{\s*width\s*:\s*100px\s*(;\s*}|})/i)
);
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class="red-text">CatPhotoApp</h2>
<main>
<p class="red-text">Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img class="smaller-image" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="https://freecatphotoapp.com/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
```

Some files were not shown because too many files have changed in this diff Show More