Feat: add new Markdown parser (#39800)

and change all the challenges to new `md` format.
This commit is contained in:
Oliver Eyton-Williams
2020-11-27 19:02:05 +01:00
committed by GitHub
parent a07f84c8ec
commit 0bd52f8bd1
2580 changed files with 113436 additions and 111979 deletions

View File

@ -6,34 +6,29 @@ videoUrl: 'https://scrimba.com/c/cnpyGs3'
forumTopicId: 16166
---
## Description
<section id='description'>
An element's <code>margin</code> controls the amount of space between an element's <code>border</code> and surrounding elements.
If you set an element's <code>margin</code> to a negative value, the element will grow larger.
</section>
# --description--
## Instructions
<section id='instructions'>
Try to set the <code>margin</code> to a negative value like the one for the red box.
Change the <code>margin</code> of the blue box to <code>-15px</code>, so it fills the entire horizontal width of the yellow box around it.
</section>
An element's `margin` controls the amount of space between an element's `border` and surrounding elements.
## Tests
<section id='tests'>
If you set an element's `margin` to a negative value, the element will grow larger.
```yml
tests:
- text: Your <code>blue-box</code> class should give elements <code>-15px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-top") === "-15px");
# --instructions--
Try to set the `margin` to a negative value like the one for the red box.
Change the `margin` of the blue box to `-15px`, so it fills the entire horizontal width of the yellow box around it.
# --hints--
Your `blue-box` class should give elements `-15px` of `margin`.
```js
assert($('.blue-box').css('margin-top') === '-15px');
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -75,14 +70,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -124,5 +112,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,9 +6,10 @@ videoUrl: 'https://scrimba.com/c/c2MvnHZ'
forumTopicId: 16630
---
## Description
<section id='description'>
CSS borders have properties like <code>style</code>, <code>color</code> and <code>width</code>.
# --description--
CSS borders have properties like `style`, `color` and `width`.
For example, if we wanted to create a red, 5 pixel border around an HTML element, we could use this class:
```html
@ -21,39 +22,53 @@ For example, if we wanted to create a red, 5 pixel border around an HTML element
</style>
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Create a class called <code>thick-green-border</code>. This class should add a 10px, solid, green border around an HTML element. Apply the class to your cat photo.
Remember that you can apply multiple classes to an element using its <code>class</code> attribute, by separating each class name with a space. For example:
<code>&lt;img class="class1 class2"&gt;</code>
</section>
Create a class called `thick-green-border`. This class should add a 10px, solid, green border around an HTML element. Apply the class to your cat photo.
## Tests
<section id='tests'>
Remember that you can apply multiple classes to an element using its `class` attribute, by separating each class name with a space. For example:
```yml
tests:
- text: Your <code>img</code> element should have the class <code>smaller-image</code>.
testString: assert($("img").hasClass("smaller-image"));
- text: Your <code>img</code> element should have the class <code>thick-green-border</code>.
testString: assert($("img").hasClass("thick-green-border"));
- text: Your image should have a border width of <code>10px</code>.
testString: assert($("img").hasClass("thick-green-border") && parseInt($("img").css("border-top-width"), 10) >= 8 && parseInt($("img").css("border-top-width"), 10) <= 12);
- text: Your image should have a border style of <code>solid</code>.
testString: assert($("img").css("border-right-style") === "solid");
- text: The border around your <code>img</code> element should be green.
testString: assert($("img").css("border-left-color") === "rgb(0, 128, 0)");
`<img class="class1 class2">`
# --hints--
Your `img` element should have the class `smaller-image`.
```js
assert($('img').hasClass('smaller-image'));
```
</section>
Your `img` element should have the class `thick-green-border`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('img').hasClass('thick-green-border'));
```
<div id='html-seed'>
Your image should have a border width of `10px`.
```js
assert(
$('img').hasClass('thick-green-border') &&
parseInt($('img').css('border-top-width'), 10) >= 8 &&
parseInt($('img').css('border-top-width'), 10) <= 12
);
```
Your image should have a border style of `solid`.
```js
assert($('img').css('border-right-style') === 'solid');
```
The border around your `img` element should be green.
```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">
@ -109,12 +124,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -175,5 +185,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,39 +6,45 @@ videoUrl: 'https://scrimba.com/c/cg4RWh4'
forumTopicId: 16633
---
## Description
<section id='description'>
Sometimes you will want to customize an element so that it has a different <code>margin</code> on each of its sides.
CSS allows you to control the <code>margin</code> of all four individual sides of an element with the <code>margin-top</code>, <code>margin-right</code>, <code>margin-bottom</code>, and <code>margin-left</code> properties.
</section>
# --description--
## Instructions
<section id='instructions'>
Give the blue box a <code>margin</code> of <code>40px</code> on its top and left side, but only <code>20px</code> on its bottom and right side.
</section>
Sometimes you will want to customize an element so that it has a different `margin` on each of its sides.
## Tests
<section id='tests'>
CSS allows you to control the `margin` of all four individual sides of an element with the `margin-top`, `margin-right`, `margin-bottom`, and `margin-left` properties.
```yml
tests:
- text: Your <code>blue-box</code> class should give the top of elements <code>40px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-top") === "40px");
- text: Your <code>blue-box</code> class should give the right of elements <code>20px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-right") === "20px");
- text: Your <code>blue-box</code> class should give the bottom of elements <code>20px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-bottom") === "20px");
- text: Your <code>blue-box</code> class should give the left of elements <code>40px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-left") === "40px");
# --instructions--
Give the blue box a `margin` of `40px` on its top and left side, but only `20px` on its bottom and right side.
# --hints--
Your `blue-box` class should give the top of elements `40px` of `margin`.
```js
assert($('.blue-box').css('margin-top') === '40px');
```
</section>
Your `blue-box` class should give the right of elements `20px` of `margin`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('.blue-box').css('margin-right') === '20px');
```
<div id='html-seed'>
Your `blue-box` class should give the bottom of elements `20px` of `margin`.
```js
assert($('.blue-box').css('margin-bottom') === '20px');
```
Your `blue-box` class should give the left of elements `40px` of `margin`.
```js
assert($('.blue-box').css('margin-left') === '40px');
```
# --seed--
## --seed-contents--
```html
<style>
@ -81,14 +87,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -134,5 +133,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,39 +6,45 @@ videoUrl: 'https://scrimba.com/c/cB7mwUw'
forumTopicId: 16634
---
## Description
<section id='description'>
Sometimes you will want to customize an element so that it has different amounts of <code>padding</code> on each of its sides.
CSS allows you to control the <code>padding</code> of all four individual sides of an element with the <code>padding-top</code>, <code>padding-right</code>, <code>padding-bottom</code>, and <code>padding-left</code> properties.
</section>
# --description--
## Instructions
<section id='instructions'>
Give the blue box a <code>padding</code> of <code>40px</code> on its top and left side, but only <code>20px</code> on its bottom and right side.
</section>
Sometimes you will want to customize an element so that it has different amounts of `padding` on each of its sides.
## Tests
<section id='tests'>
CSS allows you to control the `padding` of all four individual sides of an element with the `padding-top`, `padding-right`, `padding-bottom`, and `padding-left` properties.
```yml
tests:
- text: Your <code>blue-box</code> class should give the top of the elements <code>40px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-top") === "40px");
- text: Your <code>blue-box</code> class should give the right of the elements <code>20px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-right") === "20px");
- text: Your <code>blue-box</code> class should give the bottom of the elements <code>20px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-bottom") === "20px");
- text: Your <code>blue-box</code> class should give the left of the elements <code>40px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-left") === "40px");
# --instructions--
Give the blue box a `padding` of `40px` on its top and left side, but only `20px` on its bottom and right side.
# --hints--
Your `blue-box` class should give the top of the elements `40px` of `padding`.
```js
assert($('.blue-box').css('padding-top') === '40px');
```
</section>
Your `blue-box` class should give the right of the elements `20px` of `padding`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('.blue-box').css('padding-right') === '20px');
```
<div id='html-seed'>
Your `blue-box` class should give the bottom of the elements `20px` of `padding`.
```js
assert($('.blue-box').css('padding-bottom') === '20px');
```
Your `blue-box` class should give the left of the elements `40px` of `padding`.
```js
assert($('.blue-box').css('padding-left') === '40px');
```
# --seed--
## --seed-contents--
```html
<style>
@ -81,14 +87,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -134,5 +133,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,35 +6,38 @@ videoUrl: 'https://scrimba.com/c/cbZm2hg'
forumTopicId: 16649
---
## Description
<section id='description'>
Your cat photo currently has sharp corners. We can round out those corners with a CSS property called <code>border-radius</code>.
</section>
# --description--
## Instructions
<section id='instructions'>
You can specify a <code>border-radius</code> with pixels. Give your cat photo a <code>border-radius</code> of <code>10px</code>.
<strong>Note:</strong> This challenge allows for multiple possible solutions. For example, you may add <code>border-radius</code> to either the <code>.thick-green-border</code> class or the <code>.smaller-image</code> class.
</section>
Your cat photo currently has sharp corners. We can round out those corners with a CSS property called `border-radius`.
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: Your image element should have the class "thick-green-border".
testString: assert($("img").hasClass("thick-green-border"));
- text: Your image should have a border radius of <code>10px</code>
testString: 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');
You can specify a `border-radius` with pixels. Give your cat photo a `border-radius` of `10px`.
**Note:** This challenge allows for multiple possible solutions. For example, you may add `border-radius` to either the `.thick-green-border` class or the `.smaller-image` class.
# --hints--
Your image element should have the class "thick-green-border".
```js
assert($('img').hasClass('thick-green-border'));
```
</section>
Your image should have a border radius of `10px`
## Challenge Seed
<section id='challengeSeed'>
```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'
);
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -96,14 +99,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -165,5 +161,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,34 +6,29 @@ videoUrl: 'https://scrimba.com/c/cVJarHW'
forumTopicId: 16654
---
## Description
<section id='description'>
An element's <code>margin</code> controls the amount of space between an element's <code>border</code> and surrounding elements.
Here, we can see that the blue box and the red box are nested within the yellow box. Note that the red box has a bigger <code>margin</code> than the blue box, making it appear smaller.
When you increase the blue box's <code>margin</code>, it will increase the distance between its border and surrounding elements.
</section>
# --description--
## Instructions
<section id='instructions'>
Change the <code>margin</code> of the blue box to match that of the red box.
</section>
An element's `margin` controls the amount of space between an element's `border` and surrounding elements.
## Tests
<section id='tests'>
Here, we can see that the blue box and the red box are nested within the yellow box. Note that the red box has a bigger `margin` than the blue box, making it appear smaller.
```yml
tests:
- text: Your <code>blue-box</code> class should give elements <code>20px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-top") === "20px");
When you increase the blue box's `margin`, it will increase the distance between its border and surrounding elements.
# --instructions--
Change the `margin` of the blue box to match that of the red box.
# --hints--
Your `blue-box` class should give elements `20px` of `margin`.
```js
assert($('.blue-box').css('margin-top') === '20px');
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -76,14 +71,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -125,5 +113,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,37 +6,35 @@ videoUrl: 'https://scrimba.com/c/cED8ZC2'
forumTopicId: 301083
---
## Description
<section id='description'>
# --description--
Now let's put our Cat Photo App away for a little while and learn more about styling HTML.
You may have already noticed this, but all HTML elements are essentially little rectangles.
Three important properties control the space that surrounds each HTML element: <code>padding</code>, <code>border</code>, and <code>margin</code>.
An element's <code>padding</code> controls the amount of space between the element's content and its <code>border</code>.
Here, we can see that the blue box and the red box are nested within the yellow box. Note that the red box has more <code>padding</code> than the blue box.
When you increase the blue box's <code>padding</code>, it will increase the distance (<code>padding</code>) between the text and the border around it.
</section>
## Instructions
<section id='instructions'>
Change the <code>padding</code> of your blue box to match that of your red box.
</section>
Three important properties control the space that surrounds each HTML element: `padding`, `border`, and `margin`.
## Tests
<section id='tests'>
An element's `padding` controls the amount of space between the element's content and its `border`.
```yml
tests:
- text: Your <code>blue-box</code> class should give elements <code>20px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-top") === "20px");
Here, we can see that the blue box and the red box are nested within the yellow box. Note that the red box has more `padding` than the blue box.
When you increase the blue box's `padding`, it will increase the distance (`padding`) between the text and the border around it.
# --instructions--
Change the `padding` of your blue box to match that of your red box.
# --hints--
Your `blue-box` class should give elements `20px` of `padding`.
```js
assert($('.blue-box').css('padding-top') === '20px');
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -77,14 +75,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -124,5 +115,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,47 +6,49 @@ videoUrl: 'https://scrimba.com/c/c6bDNfp'
forumTopicId: 301084
---
## Description
# --description--
<section id='description'>
When using your variable as a CSS property value, you can attach a fallback value that your browser will revert to if the given variable is invalid.
<strong>Note:</strong> This fallback is not used to increase browser compatibility, and it will not work on IE browsers. Rather, it is used so that the browser has a color to display if it cannot find your variable.
**Note:** This fallback is not used to increase browser compatibility, and it will not work on IE browsers. Rather, it is used so that the browser has a color to display if it cannot find your variable.
Here's how you do it:
```css
background: var(--penguin-skin, black);
```
This will set background to black if your variable wasn't set.
Note that this can be useful for debugging.
This will set background to black if your variable wasn't set. Note that this can be useful for debugging.
</section>
# --instructions--
## Instructions
It looks like there is a problem with the variables supplied to the `.penguin-top` and `.penguin-bottom` classes. Rather than fix the typo, add a fallback value of `black` to the `background` property of the `.penguin-top` and `.penguin-bottom` classes.
<section id='instructions'>
It looks like there is a problem with the variables supplied to the <code>.penguin-top</code> and <code>.penguin-bottom</code> classes. Rather than fix the typo, add a fallback value of <code>black</code> to the <code>background</code> property of the <code>.penguin-top</code> and <code>.penguin-bottom</code> classes.
</section>
# --hints--
## Tests
The fallback value of `black` should be used in the `background` property of the `penguin-top` class.
<section id='tests'>
```yml
tests:
- text: The fallback value of <code>black</code> should be used in the <code>background</code> property of the <code>penguin-top</code> class.
testString: 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));
- text: The fallback value of <code>black</code> should be used in <code>background</code> property of the <code>penguin-bottom</code> class.
testString: assert(code.match(/.penguin-bottom\s*?{[\s\S]*background\s*?:\s*?var\(\s*?--pengiun-skin\s*?,\s*?black\s*?\)\s*?;[\s\S]*}/gi));
```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
)
);
```
</section>
The fallback value of `black` should be used in `background` property of the `penguin-bottom` class.
## Challenge Seed
```js
assert(
code.match(
/.penguin-bottom\s*?{[\s\S]*background\s*?:\s*?var\(\s*?--pengiun-skin\s*?,\s*?black\s*?\)\s*?;[\s\S]*}/gi
)
);
```
<section id='challengeSeed'>
# --seed--
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -255,13 +257,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -273,5 +269,3 @@ tests:
}
</style>
```
</section>

View File

@ -6,33 +6,29 @@ videoUrl: 'https://scrimba.com/c/cdRwbuW'
forumTopicId: 301085
---
## Description
<section id='description'>
When you create your variables in <code>:root</code> they will set the value of that variable for the whole page.
# --description--
When you create your variables in `:root` they will set the value of that variable for the whole page.
You can then over-write these variables by setting them again within a specific element.
</section>
## Instructions
<section id='instructions'>
Change the value of <code>--penguin-belly</code> to <code>white</code> in the <code>penguin</code> class.
</section>
# --instructions--
## Tests
<section id='tests'>
Change the value of `--penguin-belly` to `white` in the `penguin` class.
```yml
tests:
- text: The <code>penguin</code> class should reassign the <code>--penguin-belly</code> variable to <code>white</code>.
testString: assert(code.match(/.penguin\s*?{[\s\S]*--penguin-belly\s*?:\s*?white\s*?;[\s\S]*}/gi));
# --hints--
The `penguin` class should reassign the `--penguin-belly` variable to `white`.
```js
assert(
code.match(/.penguin\s*?{[\s\S]*--penguin-belly\s*?:\s*?white\s*?;[\s\S]*}/gi)
);
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -239,20 +235,10 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
.penguin {--penguin-belly: white;}
</style>
```
</section>

View File

@ -6,41 +6,47 @@ videoUrl: 'https://scrimba.com/c/cRkVmSm'
forumTopicId: 16775
---
## Description
<section id='description'>
# --description--
Now let's change the color of some of our text.
We can do this by changing the <code>style</code> of your <code>h2</code> element.
The property that is responsible for the color of an element's text is the <code>color</code> style property.
Here's how you would set your <code>h2</code> element's text color to blue:
<code>&#60;h2 style="color: blue;"&#62;CatPhotoApp&#60;/h2&#62;</code>
Note that it is a good practice to end inline <code>style</code> declarations with a <code>;</code> .
</section>
## Instructions
<section id='instructions'>
Change your <code>h2</code> element's style so that its text color is red.
</section>
We can do this by changing the `style` of your `h2` element.
## Tests
<section id='tests'>
The property that is responsible for the color of an element's text is the `color` style property.
```yml
tests:
- text: Your <code>h2</code> element should have a <code>style</code> declaration.
testString: assert($("h2").attr('style'));
- text: Your <code>h2</code> element should have color set to <code>red</code>.
testString: assert($("h2")[0].style.color === "red");
- text: Your <code>style</code> declaration should end with a <code>;</code> .
testString: assert($("h2").attr('style') && $("h2").attr('style').endsWith(';'));
Here's how you would set your `h2` element's text color to blue:
`<h2 style="color: blue;">CatPhotoApp</h2>`
Note that it is a good practice to end inline `style` declarations with a `;` .
# --instructions--
Change your `h2` element's style so that its text color is red.
# --hints--
Your `h2` element should have a `style` declaration.
```js
assert($('h2').attr('style'));
```
</section>
Your `h2` element should have color set to `red`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h2')[0].style.color === 'red');
```
<div id='html-seed'>
Your `style` declaration should end with a `;` .
```js
assert($('h2').attr('style') && $('h2').attr('style').endsWith(';'));
```
# --seed--
## --seed-contents--
```html
<h2>CatPhotoApp</h2>
@ -76,14 +82,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<h2 style="color: red;">CatPhotoApp</h2>
@ -118,5 +117,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,9 +6,9 @@ videoUrl: 'https://scrimba.com/c/c3bvDc8'
forumTopicId: 16777
---
## Description
<section id='description'>
Font size is controlled by the <code>font-size</code> CSS property, like this:
# --description--
Font size is controlled by the `font-size` CSS property, like this:
```css
h1 {
@ -16,29 +16,21 @@ h1 {
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Inside the same <code>&#60;style&#62;</code> tag that contains your <code>red-text</code> class, create an entry for <code>p</code> elements and set the <code>font-size</code> to 16 pixels (<code>16px</code>).
</section>
Inside the same `<style>` tag that contains your `red-text` class, create an entry for `p` elements and set the `font-size` to 16 pixels (`16px`).
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Between the <code>style</code> tags, give the <code>p</code> elements <code>font-size</code> of <code>16px</code>. Browser and Text zoom should be at 100%.
testString: assert(code.match(/p\s*{\s*font-size\s*:\s*16\s*px\s*;\s*}/i));
Between the `style` tags, give the `p` elements `font-size` of `16px`. Browser and Text zoom should be at 100%.
```js
assert(code.match(/p\s*{\s*font-size\s*:\s*16\s*px\s*;\s*}/i));
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -80,14 +72,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -131,5 +116,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,39 +6,33 @@ videoUrl: 'https://scrimba.com/c/cQd27Hr'
forumTopicId: 301086
---
## Description
<section id='description'>
# --description--
To create a CSS variable, you just need to give it a name with two hyphens in front of it and assign it a value like this:
```css
--penguin-skin: gray;
```
This will create a variable named <code>--penguin-skin</code> and assign it the value of <code>gray</code>.
Now you can use that variable elsewhere in your CSS to change the value of other elements to gray.
</section>
This will create a variable named `--penguin-skin` and assign it the value of `gray`. Now you can use that variable elsewhere in your CSS to change the value of other elements to gray.
## Instructions
<section id='instructions'>
In the <code>penguin</code> class, create a variable name <code>--penguin-skin</code> and give it a value of <code>gray</code>.
</section>
# --instructions--
## Tests
<section id='tests'>
In the `penguin` class, create a variable name `--penguin-skin` and give it a value of `gray`.
```yml
tests:
- text: <code>penguin</code> class should declare the <code>--penguin-skin</code> variable and assign it to <code>gray</code>.
testString: assert(code.match(/\.penguin\s*\{[^{}]*?--penguin-skin\s*:\s*gr[ae]y\s*;[^{}]*?\}/gi));
# --hints--
`penguin` class should declare the `--penguin-skin` variable and assign it to `gray`.
```js
assert(
code.match(/\.penguin\s*\{[^{}]*?--penguin-skin\s*:\s*gr[ae]y\s*;[^{}]*?\}/gi)
);
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -239,18 +233,8 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>.penguin {--penguin-skin: gray;}</style>
```
</section>

View File

@ -6,10 +6,11 @@ videoUrl: 'https://scrimba.com/c/cdRKMCk'
forumTopicId: 18190
---
## Description
<section id='description'>
You can set an element's background color with the <code>background-color</code> property.
For example, if you wanted an element's background color to be <code>green</code>, you'd put this within your <code>style</code> element:
# --description--
You can set an element's background color with the `background-color` property.
For example, if you wanted an element's background color to be `green`, you'd put this within your `style` element:
```css
.green-background {
@ -17,33 +18,33 @@ For example, if you wanted an element's background color to be <code>green</code
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Create a class called <code>silver-background</code> with the <code>background-color</code> of silver. Assign this class to your <code>div</code> element.
</section>
Create a class called `silver-background` with the `background-color` of silver. Assign this class to your `div` element.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your<code>div</code> element should have the class <code>silver-background</code>.
testString: assert($("div").hasClass("silver-background"));
- text: Your <code>div</code> element should have a silver background.
testString: assert($("div").css("background-color") === "rgb(192, 192, 192)");
- text: A class named <code>silver-background</code> should be defined within the <code>style</code> element and the value of <code>silver</code> should be assigned to the <code>background-color</code> property.
testString: assert(code.match(/\.silver-background\s*{\s*background-color:\s*silver;\s*}/));
Your`div` element should have the class `silver-background`.
```js
assert($('div').hasClass('silver-background'));
```
</section>
Your `div` element should have a silver background.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('div').css('background-color') === 'rgb(192, 192, 192)');
```
<div id='html-seed'>
A class named `silver-background` should be defined within the `style` element and the value of `silver` should be assigned to the `background-color` property.
```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">
@ -106,14 +107,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -179,5 +173,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,45 +6,70 @@ videoUrl: 'https://scrimba.com/c/cM9MRsJ'
forumTopicId: 18200
---
## Description
<section id='description'>
# --description--
In addition to specifying common fonts that are found on most operating systems, we can also specify non-standard, custom web fonts for use on our website. There are many sources for web fonts on the Internet. For this example we will focus on the Google Fonts library.
<a href='https://fonts.google.com/' target='_blank'>Google Fonts</a> is a free library of web fonts that you can use in your CSS by referencing the font's URL.
[Google Fonts](https://fonts.google.com/) is a free library of web fonts that you can use in your CSS by referencing the font's URL.
So, let's go ahead and import and apply a Google font (note that if Google is blocked in your country, you will need to skip this challenge).
To import a Google Font, you can copy the font's URL from the Google Fonts library and then paste it in your HTML. For this challenge, we'll import the <code>Lobster</code> font. To do this, copy the following code snippet and paste it into the top of your code editor (before the opening <code>style</code> element):
<code>&#60;link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"&#62;</code>
Now you can use the <code>Lobster</code> font in your CSS by using <code>Lobster</code> as the FAMILY_NAME as in the following example:<br><code>font-family: FAMILY_NAME, GENERIC_NAME;</code>.
To import a Google Font, you can copy the font's URL from the Google Fonts library and then paste it in your HTML. For this challenge, we'll import the `Lobster` font. To do this, copy the following code snippet and paste it into the top of your code editor (before the opening `style` element):
`<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">`
Now you can use the `Lobster` font in your CSS by using `Lobster` as the FAMILY_NAME as in the following example:
`font-family: FAMILY_NAME, GENERIC_NAME;`.
The GENERIC_NAME is optional, and is a fallback font in case the other specified font is not available. This is covered in the next challenge.
Family names are case-sensitive and need to be wrapped in quotes if there is a space in the name. For example, you need quotes to use the <code>"Open Sans"</code> font, but not to use the <code>Lobster</code> font.
</section>
## Instructions
<section id='instructions'>
Import the Lobster font to your web page. Then, use an element selector to set <code>Lobster</code> as the <code>font-family</code> for your <code>h2</code> element.
</section>
Family names are case-sensitive and need to be wrapped in quotes if there is a space in the name. For example, you need quotes to use the `"Open Sans"` font, but not to use the `Lobster` font.
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: You should import the <code>Lobster</code> font.
testString: assert(new RegExp("googleapis", "gi").test(code));
- text: Your <code>h2</code> element should use the font <code>Lobster</code>.
testString: assert($("h2").css("font-family").match(/lobster/i));
- text: You should only use an <code>h2</code> element selector to change the font.
testString: assert(/\s*[^\.]h2\s*\{\s*font-family\:\s*(['"]?)Lobster\1\s*(;\s*\}|\})/gi.test(code));
- text: Your <code>p</code> element should still use the font <code>monospace</code>.
testString: assert($("p").css("font-family").match(/monospace/i));
Import the Lobster font to your web page. Then, use an element selector to set `Lobster` as the `font-family` for your `h2` element.
# --hints--
You should import the `Lobster` font.
```js
assert(new RegExp('googleapis', 'gi').test(code));
```
</section>
Your `h2` element should use the font `Lobster`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
$('h2')
.css('font-family')
.match(/lobster/i)
);
```
<div id='html-seed'>
You should only use an `h2` element selector to change the font.
```js
assert(
/\s*[^\.]h2\s*\{\s*font-family\:\s*(['"]?)Lobster\1\s*(;\s*\}|\})/gi.test(
code
)
);
```
Your `p` element should still use the font `monospace`.
```js
assert(
$('p')
.css('font-family')
.match(/monospace/i)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -91,14 +116,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -149,5 +167,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,34 +6,35 @@ videoUrl: ''
forumTopicId: 301087
---
## Description
<section id='description'>
# --description--
When working with CSS you will likely run into browser compatibility issues at some point. This is why it's important to provide browser fallbacks to avoid potential problems.
When your browser parses the CSS of a webpage, it ignores any properties that it doesn't recognize or support. For example, if you use a CSS variable to assign a background color on a site, Internet Explorer will ignore the background color because it does not support CSS variables. In that case, the browser will use whatever value it has for that property. If it can't find any other value set for that property, it will revert to the default value, which is typically not ideal.
This means that if you do want to provide a browser fallback, it's as easy as providing another more widely supported value immediately before your declaration. That way an older browser will have something to fall back on, while a newer browser will just interpret whatever declaration comes later in the cascade.
</section>
## Instructions
<section id='instructions'>
It looks like a variable is being used to set the background color of the <code>.red-box</code> class. Let's improve our browser compatibility by adding another <code>background</code> declaration right before the existing declaration and set its value to red.
</section>
# --instructions--
## Tests
<section id='tests'>
It looks like a variable is being used to set the background color of the `.red-box` class. Let's improve our browser compatibility by adding another `background` declaration right before the existing declaration and set its value to red.
```yml
tests:
- text: Your <code>.red-box</code> rule should include a fallback with the <code>background</code> set to red immediately before the existing <code>background</code> declaration.
testString: 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));
# --hints--
Your `.red-box` rule should include a fallback with the `background` set to red immediately before the existing `background` declaration.
```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
)
);
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -50,15 +51,7 @@ tests:
<div class="red-box"></div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -74,5 +67,3 @@ tests:
</style>
<div class="red-box"></div>
```
</section>

View File

@ -6,34 +6,31 @@ videoUrl: 'https://scrimba.com/c/cyLZZhZ'
forumTopicId: 301088
---
## Description
<section id='description'>
# --description--
When you create a variable, it is available for you to use inside the selector in which you create it. It also is available in any of that selector's descendants. This happens because CSS variables are inherited, just like ordinary properties.
To make use of inheritance, CSS variables are often defined in the <dfn>:root</dfn> element.
<code>:root</code> is a <dfn>pseudo-class</dfn> selector that matches the root element of the document, usually the <code>html</code> element. By creating your variables in <code>:root</code>, they will be available globally and can be accessed from any other selector in the style sheet.
</section>
## Instructions
<section id='instructions'>
Define a variable named <code>--penguin-belly</code> in the <code>:root</code> selector and give it the value of <code>pink</code>. You can then see that the variable is inherited and that all the child elements which use it get pink backgrounds.
</section>
`:root` is a <dfn>pseudo-class</dfn> selector that matches the root element of the document, usually the `html` element. By creating your variables in `:root`, they will be available globally and can be accessed from any other selector in the style sheet.
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: The <code>--penguin-belly</code> variable should be declared in the <code>:root</code> and assigned the value <code>pink</code>.
testString: assert(code.match(/:root\s*?{[\s\S]*--penguin-belly\s*?:\s*?pink\s*?;[\s\S]*}/gi));
Define a variable named `--penguin-belly` in the `:root` selector and give it the value of `pink`. You can then see that the variable is inherited and that all the child elements which use it get pink backgrounds.
# --hints--
The `--penguin-belly` variable should be declared in the `:root` and assigned the value `pink`.
```js
assert(
code.match(/:root\s*?{[\s\S]*--penguin-belly\s*?:\s*?pink\s*?;[\s\S]*}/gi)
);
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -239,18 +236,8 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>:root {--penguin-belly: pink;}</style>
```
</section>

View File

@ -6,47 +6,85 @@ videoUrl: 'https://scrimba.com/c/c9bmdtR'
forumTopicId: 18204
---
## Description
<section id='description'>
Now we've proven that every HTML page has a <code>body</code> element, and that its <code>body</code> element can also be styled with CSS.
Remember, you can style your <code>body</code> element just like any other HTML element, and all your other elements will inherit your <code>body</code> element's styles.
</section>
# --description--
## Instructions
<section id='instructions'>
First, create a <code>h1</code> element with the text <code>Hello World</code>
Then, let's give all elements on your page the color of <code>green</code> by adding <code>color: green;</code> to your <code>body</code> element's style declaration.
Finally, give your <code>body</code> element the font-family of <code>monospace</code> by adding <code>font-family: monospace;</code> to your <code>body</code> element's style declaration.
</section>
Now we've proven that every HTML page has a `body` element, and that its `body` element can also be styled with CSS.
## Tests
<section id='tests'>
Remember, you can style your `body` element just like any other HTML element, and all your other elements will inherit your `body` element's styles.
```yml
tests:
- text: You should create an <code>h1</code> element.
testString: assert(($("h1").length > 0));
- text: Your <code>h1</code> element should have the text <code>Hello World</code>.
testString: assert(($("h1").length > 0 && $("h1").text().match(/hello world/i)));
- text: Your <code>h1</code> element should have a closing tag.
testString: assert(code.match(/<\/h1>/g) && code.match(/<h1/g) && code.match(/<\/h1>/g).length === code.match(/<h1/g).length);
- text: Your <code>body</code> element should have the <code>color</code> property of <code>green</code>.
testString: assert(($("body").css("color") === "rgb(0, 128, 0)"));
- text: Your <code>body</code> element should have the <code>font-family</code> property of <code>monospace</code>.
testString: assert(($("body").css("font-family").match(/monospace/i)));
- text: Your <code>h1</code> element should inherit the font <code>monospace</code> from your <code>body</code> element.
testString: assert(($("h1").length > 0 && $("h1").css("font-family").match(/monospace/i)));
- text: Your <code>h1</code> element should inherit the color green from your <code>body</code> element.
testString: assert(($("h1").length > 0 && $("h1").css("color") === "rgb(0, 128, 0)"));
# --instructions--
First, create a `h1` element with the text `Hello World`
Then, let's give all elements on your page the color of `green` by adding `color: green;` to your `body` element's style declaration.
Finally, give your `body` element the font-family of `monospace` by adding `font-family: monospace;` to your `body` element's style declaration.
# --hints--
You should create an `h1` element.
```js
assert($('h1').length > 0);
```
</section>
Your `h1` element should have the text `Hello World`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
$('h1').length > 0 &&
$('h1')
.text()
.match(/hello world/i)
);
```
<div id='html-seed'>
Your `h1` element should have a closing tag.
```js
assert(
code.match(/<\/h1>/g) &&
code.match(/<h1/g) &&
code.match(/<\/h1>/g).length === code.match(/<h1/g).length
);
```
Your `body` element should have the `color` property of `green`.
```js
assert($('body').css('color') === 'rgb(0, 128, 0)');
```
Your `body` element should have the `font-family` property of `monospace`.
```js
assert(
$('body')
.css('font-family')
.match(/monospace/i)
);
```
Your `h1` element should inherit the font `monospace` from your `body` element.
```js
assert(
$('h1').length > 0 &&
$('h1')
.css('font-family')
.match(/monospace/i)
);
```
Your `h1` element should inherit the color green from your `body` element.
```js
assert($('h1').length > 0 && $('h1').css('color') === 'rgb(0, 128, 0)');
```
# --seed--
## --seed-contents--
```html
<style>
@ -57,14 +95,7 @@ tests:
</style>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -77,5 +108,3 @@ tests:
</style>
<h1>Hello World!</h1>
```
</section>

View File

@ -6,34 +6,31 @@ videoUrl: 'https://scrimba.com/c/c2MvrcB'
forumTopicId: 18229
---
## Description
<section id='description'>
In addition to pixels, you can also specify the <code>border-radius</code> using a percentage.
</section>
# --description--
## Instructions
<section id='instructions'>
Give your cat photo a <code>border-radius</code> of <code>50%</code>.
</section>
In addition to pixels, you can also specify the `border-radius` using a percentage.
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: Your image should have a border radius of <code>50%</code>, making it perfectly circular.
testString: assert(parseInt($("img").css("border-top-left-radius")) > 48);
- text: The <code>border-radius</code> value should use a percentage value of <code>50%</code>.
testString: assert(code.match(/50%/g));
Give your cat photo a `border-radius` of `50%`.
# --hints--
Your image should have a border radius of `50%`, making it perfectly circular.
```js
assert(parseInt($('img').css('border-top-left-radius')) > 48);
```
</section>
The `border-radius` value should use a percentage value of `50%`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/50%/g));
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -96,14 +93,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -166,5 +156,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,47 +6,67 @@ videoUrl: 'https://scrimba.com/c/cm24rcp'
forumTopicId: 18249
---
## Description
<section id='description'>
Yay! We just proved that inline styles will override all the CSS declarations in your <code>style</code> element.
# --description--
Yay! We just proved that inline styles will override all the CSS declarations in your `style` element.
But wait. There's one last way to override CSS. This is the most powerful method of all. But before we do it, let's talk about why you would ever want to override CSS.
In many situations, you will use CSS libraries. These may accidentally override your own CSS. So when you absolutely need to be sure that an element has specific CSS, you can use <code>!important</code>
Let's go all the way back to our <code>pink-text</code> class declaration. Remember that our <code>pink-text</code> class was overridden by subsequent class declarations, id declarations, and inline styles.
</section>
## Instructions
<section id='instructions'>
Let's add the keyword <code>!important</code> to your pink-text element's color declaration to make 100% sure that your <code>h1</code> element will be pink.
In many situations, you will use CSS libraries. These may accidentally override your own CSS. So when you absolutely need to be sure that an element has specific CSS, you can use `!important`
Let's go all the way back to our `pink-text` class declaration. Remember that our `pink-text` class was overridden by subsequent class declarations, id declarations, and inline styles.
# --instructions--
Let's add the keyword `!important` to your pink-text element's color declaration to make 100% sure that your `h1` element will be pink.
An example of how to do this is:
<code>color: red !important;</code>
</section>
## Tests
<section id='tests'>
`color: red !important;`
```yml
tests:
- text: Your <code>h1</code> element should have the class <code>pink-text</code>.
testString: assert($("h1").hasClass("pink-text"));
- text: Your <code>h1</code> element should have the class <code>blue-text</code>.
testString: assert($("h1").hasClass("blue-text"));
- text: Your <code>h1</code> element should have the id of <code>orange-text</code>.
testString: assert($("h1").attr("id") === "orange-text");
- text: Your <code>h1</code> element should have the inline style of <code>color&#58; white</code>.
testString: assert(code.match(/<h1.*style/gi) && code.match(/<h1.*style.*color\s*?:/gi));
- text: Your <code>pink-text</code> class declaration should have the <code>!important</code> keyword to override all other declarations.
testString: assert(code.match(/\.pink-text\s*?\{[\s\S]*?color:.*pink.*!important\s*;?[^\.]*\}/g));
- text: Your <code>h1</code> element should be pink.
testString: assert($("h1").css("color") === "rgb(255, 192, 203)");
# --hints--
Your `h1` element should have the class `pink-text`.
```js
assert($('h1').hasClass('pink-text'));
```
</section>
Your `h1` element should have the class `blue-text`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h1').hasClass('blue-text'));
```
<div id='html-seed'>
Your `h1` element should have the id of `orange-text`.
```js
assert($('h1').attr('id') === 'orange-text');
```
Your `h1` element should have the inline style of `color: white`.
```js
assert(code.match(/<h1.*style/gi) && code.match(/<h1.*style.*color\s*?:/gi));
```
Your `pink-text` class declaration should have the `!important` keyword to override all other declarations.
```js
assert(
code.match(/\.pink-text\s*?\{[\s\S]*?color:.*pink.*!important\s*;?[^\.]*\}/g)
);
```
Your `h1` element should be pink.
```js
assert($('h1').css('color') === 'rgb(255, 192, 203)');
```
# --seed--
## --seed-contents--
```html
<style>
@ -68,14 +88,7 @@ tests:
<h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -96,5 +109,3 @@ tests:
</style>
<h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
```
</section>

View File

@ -6,19 +6,23 @@ videoUrl: 'https://scrimba.com/c/cRkpDhB'
forumTopicId: 18251
---
## Description
<section id='description'>
We just proved that browsers read CSS from top to bottom in order of their declaration. That means that, in the event of a conflict, the browser will use whichever CSS declaration came last. Notice that if we even had put <code>blue-text</code> before <code>pink-text</code> in our <code>h1</code> element's classes, it would still look at the declaration order and not the order of their use!
But we're not done yet. There are other ways that you can override CSS. Do you remember id attributes?
Let's override your <code>pink-text</code> and <code>blue-text</code> classes, and make your <code>h1</code> element orange, by giving the <code>h1</code> element an id and then styling that id.
</section>
# --description--
## Instructions
<section id='instructions'>
Give your <code>h1</code> element the <code>id</code> attribute of <code>orange-text</code>. Remember, id styles look like this:
<code>&#60;h1 id="orange-text"&#62;</code>
Leave the <code>blue-text</code> and <code>pink-text</code> classes on your <code>h1</code> element.
Create a CSS declaration for your <code>orange-text</code> id in your <code>style</code> element. Here's an example of what this looks like:
We just proved that browsers read CSS from top to bottom in order of their declaration. That means that, in the event of a conflict, the browser will use whichever CSS declaration came last. Notice that if we even had put `blue-text` before `pink-text` in our `h1` element's classes, it would still look at the declaration order and not the order of their use!
But we're not done yet. There are other ways that you can override CSS. Do you remember id attributes?
Let's override your `pink-text` and `blue-text` classes, and make your `h1` element orange, by giving the `h1` element an id and then styling that id.
# --instructions--
Give your `h1` element the `id` attribute of `orange-text`. Remember, id styles look like this:
`<h1 id="orange-text">`
Leave the `blue-text` and `pink-text` classes on your `h1` element.
Create a CSS declaration for your `orange-text` id in your `style` element. Here's an example of what this looks like:
```css
#brown-text {
@ -26,37 +30,55 @@ Create a CSS declaration for your <code>orange-text</code> id in your <code>styl
}
```
<strong>Note:</strong> It doesn't matter whether you declare this CSS above or below pink-text class, since id attribute will always take precedence.
</section>
**Note:** It doesn't matter whether you declare this CSS above or below pink-text class, since id attribute will always take precedence.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your <code>h1</code> element should have the class <code>pink-text</code>.
testString: assert($("h1").hasClass("pink-text"));
- text: Your <code>h1</code> element should have the class <code>blue-text</code>.
testString: assert($("h1").hasClass("blue-text"));
- text: Your <code>h1</code> element should have the id of <code>orange-text</code>.
testString: assert($("h1").attr("id") === "orange-text");
- text: There should be only one <code>h1</code> element.
testString: assert(($("h1").length === 1));
- text: Your <code>orange-text</code> id should have a CSS declaration.
testString: assert(code.match(/#orange-text\s*{/gi));
- text: Your <code>h1</code> should not have any <code>style</code> attributes.
testString: assert(!code.match(/<h1.*style.*>/gi));
- text: Your <code>h1</code> element should be orange.
testString: assert($("h1").css("color") === "rgb(255, 165, 0)");
Your `h1` element should have the class `pink-text`.
```js
assert($('h1').hasClass('pink-text'));
```
</section>
Your `h1` element should have the class `blue-text`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h1').hasClass('blue-text'));
```
<div id='html-seed'>
Your `h1` element should have the id of `orange-text`.
```js
assert($('h1').attr('id') === 'orange-text');
```
There should be only one `h1` element.
```js
assert($('h1').length === 1);
```
Your `orange-text` id should have a CSS declaration.
```js
assert(code.match(/#orange-text\s*{/gi));
```
Your `h1` should not have any `style` attributes.
```js
assert(!code.match(/<h1.*style.*>/gi));
```
Your `h1` element should be orange.
```js
assert($('h1').css('color') === 'rgb(255, 165, 0)');
```
# --seed--
## --seed-contents--
```html
<style>
@ -75,14 +97,7 @@ tests:
<h1 class="pink-text blue-text">Hello World!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -103,5 +118,3 @@ tests:
</style>
<h1 id="orange-text" class="pink-text blue-text">Hello World!</h1>
```
</section>

View File

@ -6,43 +6,55 @@ videoUrl: 'https://scrimba.com/c/cGJDRha'
forumTopicId: 18252
---
## Description
<section id='description'>
So we've proven that id declarations override class declarations, regardless of where they are declared in your <code>style</code> element CSS.
# --description--
So we've proven that id declarations override class declarations, regardless of where they are declared in your `style` element CSS.
There are other ways that you can override CSS. Do you remember inline styles?
</section>
## Instructions
<section id='instructions'>
Use an inline style to try to make our <code>h1</code> element white. Remember, in line styles look like this:
<code>&#60;h1 style="color: green;"&#62;</code>
Leave the <code>blue-text</code> and <code>pink-text</code> classes on your <code>h1</code> element.
</section>
# --instructions--
## Tests
<section id='tests'>
Use an inline style to try to make our `h1` element white. Remember, in line styles look like this:
```yml
tests:
- text: Your <code>h1</code> element should have the class <code>pink-text</code>.
testString: assert($("h1").hasClass("pink-text"));
- text: Your <code>h1</code> element should have the class <code>blue-text</code>.
testString: assert($("h1").hasClass("blue-text"));
- text: Your <code>h1</code> element should have the id of <code>orange-text</code>.
testString: assert($("h1").attr("id") === "orange-text");
- text: Your <code>h1</code> element should have an inline style.
testString: assert(document.querySelector('h1[style]'));
- text: Your <code>h1</code> element should be white.
testString: assert($("h1").css("color") === "rgb(255, 255, 255)");
`<h1 style="color: green;">`
Leave the `blue-text` and `pink-text` classes on your `h1` element.
# --hints--
Your `h1` element should have the class `pink-text`.
```js
assert($('h1').hasClass('pink-text'));
```
</section>
Your `h1` element should have the class `blue-text`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h1').hasClass('blue-text'));
```
<div id='html-seed'>
Your `h1` element should have the id of `orange-text`.
```js
assert($('h1').attr('id') === 'orange-text');
```
Your `h1` element should have an inline style.
```js
assert(document.querySelector('h1[style]'));
```
Your `h1` element should be white.
```js
assert($('h1').css('color') === 'rgb(255, 255, 255)');
```
# --seed--
## --seed-contents--
```html
<style>
@ -64,14 +76,7 @@ tests:
<h1 id="orange-text" class="pink-text blue-text">Hello World!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -92,5 +97,3 @@ tests:
</style>
<h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
```
</section>

View File

@ -6,44 +6,55 @@ videoUrl: 'https://scrimba.com/c/cGJDQug'
forumTopicId: 18253
---
## Description
<section id='description'>
Our "pink-text" class overrode our <code>body</code> element's CSS declaration!
We just proved that our classes will override the <code>body</code> element's CSS. So the next logical question is, what can we do to override our <code>pink-text</code> class?
</section>
# --description--
Our "pink-text" class overrode our `body` element's CSS declaration!
We just proved that our classes will override the `body` element's CSS. So the next logical question is, what can we do to override our `pink-text` class?
# --instructions--
Create an additional CSS class called `blue-text` that gives an element the color blue. Make sure it's below your `pink-text` class declaration.
Apply the `blue-text` class to your `h1` element in addition to your `pink-text` class, and let's see which one wins.
## Instructions
<section id='instructions'>
Create an additional CSS class called <code>blue-text</code> that gives an element the color blue. Make sure it's below your <code>pink-text</code> class declaration.
Apply the <code>blue-text</code> class to your <code>h1</code> element in addition to your <code>pink-text</code> class, and let's see which one wins.
Applying multiple class attributes to a HTML element is done with a space between them like this:
<code>class="class1 class2"</code>
<strong>Note:</strong> It doesn't matter which order the classes are listed in the HTML element.
However, the order of the <code>class</code> declarations in the <code>&#60;style&#62;</code> section is what is important. The second declaration will always take precedence over the first. Because <code>.blue-text</code> is declared second, it overrides the attributes of <code>.pink-text</code>
</section>
## Tests
<section id='tests'>
`class="class1 class2"`
```yml
tests:
- text: Your <code>h1</code> element should have the class <code>pink-text</code>.
testString: assert($("h1").hasClass("pink-text"));
- text: Your <code>h1</code> element should have the class <code>blue-text</code>.
testString: assert($("h1").hasClass("blue-text"));
- text: Both <code>blue-text</code> and <code>pink-text</code> should belong to the same <code>h1</code> element.
testString: assert($(".pink-text").hasClass("blue-text"));
- text: Your <code>h1</code> element should be blue.
testString: assert($("h1").css("color") === "rgb(0, 0, 255)");
**Note:** It doesn't matter which order the classes are listed in the HTML element.
However, the order of the `class` declarations in the `<style>` section is what is important. The second declaration will always take precedence over the first. Because `.blue-text` is declared second, it overrides the attributes of `.pink-text`
# --hints--
Your `h1` element should have the class `pink-text`.
```js
assert($('h1').hasClass('pink-text'));
```
</section>
Your `h1` element should have the class `blue-text`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h1').hasClass('blue-text'));
```
<div id='html-seed'>
Both `blue-text` and `pink-text` should belong to the same `h1` element.
```js
assert($('.pink-text').hasClass('blue-text'));
```
Your `h1` element should be blue.
```js
assert($('h1').css('color') === 'rgb(0, 0, 255)');
```
# --seed--
## --seed-contents--
```html
<style>
@ -59,14 +70,7 @@ tests:
<h1 class="pink-text">Hello World!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -85,5 +89,3 @@ tests:
</style>
<h1 class="pink-text blue-text">Hello World!</h1>
```
</section>

View File

@ -6,39 +6,43 @@ videoUrl: 'https://scrimba.com/c/cZ8wnHv'
forumTopicId: 18258
---
## Description
<section id='description'>
# --description--
Sometimes your HTML elements will receive multiple styles that conflict with one another.
For example, your <code>h1</code> element can't be both green and pink at the same time.
Let's see what happens when we create a class that makes text pink, then apply it to an element. Will our class <em>override</em> the <code>body</code> element's <code>color: green;</code> CSS property?
</section>
## Instructions
<section id='instructions'>
Create a CSS class called <code>pink-text</code> that gives an element the color pink.
Give your <code>h1</code> element the class of <code>pink-text</code>.
</section>
For example, your `h1` element can't be both green and pink at the same time.
## Tests
<section id='tests'>
Let's see what happens when we create a class that makes text pink, then apply it to an element. Will our class *override* the `body` element's `color: green;` CSS property?
```yml
tests:
- text: Your <code>h1</code> element should have the class <code>pink-text</code>.
testString: assert($("h1").hasClass("pink-text"));
- text: Your <code>&#60;style&#62;</code> should have a <code>pink-text</code> CSS class that changes the <code>color</code>.
testString: assert(code.match(/\.pink-text\s*\{\s*color\s*:\s*.+\s*;\s*\}/g));
- text: Your <code>h1</code> element should be pink.
testString: assert($("h1").css("color") === "rgb(255, 192, 203)");
# --instructions--
Create a CSS class called `pink-text` that gives an element the color pink.
Give your `h1` element the class of `pink-text`.
# --hints--
Your `h1` element should have the class `pink-text`.
```js
assert($('h1').hasClass('pink-text'));
```
</section>
Your `<style>` should have a `pink-text` CSS class that changes the `color`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/\.pink-text\s*\{\s*color\s*:\s*.+\s*;\s*\}/g));
```
<div id='html-seed'>
Your `h1` element should be pink.
```js
assert($('h1').css('color') === 'rgb(255, 192, 203)');
```
# --seed--
## --seed-contents--
```html
<style>
@ -51,14 +55,7 @@ tests:
<h1>Hello World!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -72,7 +69,4 @@ tests:
}
</style>
<h1 class="pink-text">Hello World!</h1>
```
</section>

View File

@ -6,10 +6,11 @@ videoUrl: 'https://scrimba.com/c/c3bvpCg'
forumTopicId: 18278
---
## Description
<section id='description'>
You can set which font an element should use, by using the <code>font-family</code> property.
For example, if you wanted to set your <code>h2</code> element's font to <code>sans-serif</code>, you would use the following CSS:
# --description--
You can set which font an element should use, by using the `font-family` property.
For example, if you wanted to set your `h2` element's font to `sans-serif`, you would use the following CSS:
```css
h2 {
@ -17,29 +18,26 @@ h2 {
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Make all of your <code>p</code> elements use the <code>monospace</code> font.
</section>
Make all of your `p` elements use the `monospace` font.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your <code>p</code> elements should use the font <code>monospace</code>.
testString: assert($("p").not(".red-text").css("font-family").match(/monospace/i));
Your `p` elements should use the font `monospace`.
```js
assert(
$('p')
.not('.red-text')
.css('font-family')
.match(/monospace/i)
);
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<style>
@ -85,14 +83,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -138,5 +129,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,36 +6,33 @@ videoUrl: 'https://scrimba.com/c/cN6MEc2'
forumTopicId: 18279
---
## Description
<section id='description'>
In addition to classes, each HTML element can also have an <code>id</code> attribute.
There are several benefits to using <code>id</code> attributes: You can use an <code>id</code> to style a single element and later you'll learn that you can use them to select and modify specific elements with JavaScript.
<code>id</code> attributes should be unique. Browsers won't enforce this, but it is a widely agreed upon best practice. So please don't give more than one element the same <code>id</code> attribute.
Here's an example of how you give your <code>h2</code> element the id of <code>cat-photo-app</code>:
<code>&#60;h2 id="cat-photo-app"></code>
</section>
# --description--
## Instructions
<section id='instructions'>
Give your <code>form</code> element the id <code>cat-photo-form</code>.
</section>
In addition to classes, each HTML element can also have an `id` attribute.
## Tests
<section id='tests'>
There are several benefits to using `id` attributes: You can use an `id` to style a single element and later you'll learn that you can use them to select and modify specific elements with JavaScript.
```yml
tests:
- text: Your <code>form</code> element should have the id of <code>cat-photo-form</code>.
testString: assert($("form").attr("id") === "cat-photo-form");
`id` attributes should be unique. Browsers won't enforce this, but it is a widely agreed upon best practice. So please don't give more than one element the same `id` attribute.
Here's an example of how you give your `h2` element the id of `cat-photo-app`:
`<h2 id="cat-photo-app">`
# --instructions--
Give your `form` element the id `cat-photo-form`.
# --hints--
Your `form` element should have the id of `cat-photo-form`.
```js
assert($('form').attr('id') === 'cat-photo-form');
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -102,14 +99,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -175,5 +165,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,10 +6,11 @@ videoUrl: 'https://scrimba.com/c/cM9MmCP'
forumTopicId: 18282
---
## Description
<section id='description'>
CSS has a property called <code>width</code> that controls an element's width. Just like with fonts, we'll use <code>px</code> (pixels) to specify the image's width.
For example, if we wanted to create a CSS class called <code>larger-image</code> that gave HTML elements a width of 500 pixels, we'd use:
# --description--
CSS has a property called `width` that controls an element's width. Just like with fonts, we'll use `px` (pixels) to specify the image's width.
For example, if we wanted to create a CSS class called `larger-image` that gave HTML elements a width of 500 pixels, we'd use:
```html
<style>
@ -19,31 +20,33 @@ For example, if we wanted to create a CSS class called <code>larger-image</code>
</style>
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Create a class called <code>smaller-image</code> and use it to resize the image so that it's only 100 pixels wide.
</section>
Create a class called `smaller-image` and use it to resize the image so that it's only 100 pixels wide.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your <code>img</code> element should have the class <code>smaller-image</code>.
testString: assert($("img[src='https://bit.ly/fcc-relaxing-cat']").attr('class') === "smaller-image");
- text: Your image should be 100 pixels wide.
testString: assert($("img").width() < 200 && code.match(/\.smaller-image\s*{\s*width\s*:\s*100px\s*(;\s*}|})/i));
Your `img` element should have the class `smaller-image`.
```js
assert(
$("img[src='https://bit.ly/fcc-relaxing-cat']").attr('class') ===
'smaller-image'
);
```
</section>
Your image should be 100 pixels wide.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
$('img').width() < 200 &&
code.match(/\.smaller-image\s*{\s*width\s*:\s*100px\s*(;\s*}|})/i)
);
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -95,14 +98,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -157,5 +153,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,11 +6,13 @@ videoUrl: 'https://scrimba.com/c/cpVKBfQ'
forumTopicId: 18304
---
## Description
<section id='description'>
There are several default fonts that are available in all browsers. These generic font families include <code>monospace</code>, <code>serif</code> and <code>sans-serif</code>
# --description--
There are several default fonts that are available in all browsers. These generic font families include `monospace`, `serif` and `sans-serif`
When one font isn't available, you can tell the browser to "degrade" to another font.
For example, if you wanted an element to use the <code>Helvetica</code> font, but degrade to the <code>sans-serif</code> font when <code>Helvetica</code> isn't available, you will specify it as follows:
For example, if you wanted an element to use the `Helvetica` font, but degrade to the `sans-serif` font when `Helvetica` isn't available, you will specify it as follows:
```css
p {
@ -19,37 +21,52 @@ p {
```
Generic font family names are not case-sensitive. Also, they do not need quotes because they are CSS keywords.
</section>
## Instructions
<section id='instructions'>
To begin, apply the <code>monospace</code> font to the <code>h2</code> element, so that it now has two fonts - <code>Lobster</code> and <code>monospace</code>.
In the last challenge, you imported the <code>Lobster</code> font using the <code>link</code> tag. Now comment out that import of the <code>Lobster</code> font (using the HTML comments you learned before) from Google Fonts so that it isn't available anymore. Notice how your <code>h2</code> element degrades to the <code>monospace</code> font.
<strong>Note:</strong> If you have the Lobster font installed on your computer, you won't see the degradation because your browser is able to find the font.
</section>
# --instructions--
## Tests
<section id='tests'>
To begin, apply the `monospace` font to the `h2` element, so that it now has two fonts - `Lobster` and `monospace`.
```yml
tests:
- text: Your h2 element should use the font <code>Lobster</code>.
testString: assert($("h2").css("font-family").match(/^"?lobster/i));
- text: Your h2 element should degrade to the font <code>monospace</code> when <code>Lobster</code> is not available.
testString: assert(/\s*h2\s*\{\s*font-family\:\s*(\'|")?Lobster(\'|")?,\s*monospace\s*;\s*\}/gi.test(code));
- text: You should comment out your call to Google for the <code>Lobster</code> font by putting <code>&#60;!--</code> in front of it.
testString: assert(new RegExp("<!--[^fc]", "gi").test(code));
- text: You should close your comment by adding <code>--&#62;</code>.
testString: assert(new RegExp("[^fc]-->", "gi").test(code));
In the last challenge, you imported the `Lobster` font using the `link` tag. Now comment out that import of the `Lobster` font (using the HTML comments you learned before) from Google Fonts so that it isn't available anymore. Notice how your `h2` element degrades to the `monospace` font.
**Note:** If you have the Lobster font installed on your computer, you won't see the degradation because your browser is able to find the font.
# --hints--
Your h2 element should use the font `Lobster`.
```js
assert(
$('h2')
.css('font-family')
.match(/^"?lobster/i)
);
```
</section>
Your h2 element should degrade to the font `monospace` when `Lobster` is not available.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
/\s*h2\s*\{\s*font-family\:\s*(\'|")?Lobster(\'|")?,\s*monospace\s*;\s*\}/gi.test(
code
)
);
```
<div id='html-seed'>
You should comment out your call to Google for the `Lobster` font by putting `<!--` in front of it.
```js
assert(new RegExp('<!--[^fc]', 'gi').test(code));
```
You should close your comment by adding `-->`.
```js
assert(new RegExp('[^fc]-->', 'gi').test(code));
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -101,14 +118,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<!--<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">-->
@ -159,5 +169,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,40 +6,48 @@ videoUrl: 'https://scrimba.com/c/cRkVbsQ'
forumTopicId: 18311
---
## Description
<section id='description'>
Classes allow you to use the same CSS styles on multiple HTML elements. You can see this by applying your <code>red-text</code> class to the first <code>p</code> element.
</section>
# --description--
## Instructions
<section id='instructions'>
Classes allow you to use the same CSS styles on multiple HTML elements. You can see this by applying your `red-text` class to the first `p` element.
</section>
# --hints--
## Tests
<section id='tests'>
```yml
tests:
- text: Your <code>h2</code> element should be red.
testString: assert($("h2").css("color") === "rgb(255, 0, 0)");
- text: Your <code>h2</code> element should have the class <code>red-text</code>.
testString: assert($("h2").hasClass("red-text"));
- text: Your first <code>p</code> element should be red.
testString: assert($("p:eq(0)").css("color") === "rgb(255, 0, 0)");
- text: Your second and third <code>p</code> elements should not be red.
testString: assert(!($("p:eq(1)").css("color") === "rgb(255, 0, 0)") && !($("p:eq(2)").css("color") === "rgb(255, 0, 0)"));
- text: Your first <code>p</code> element should have the class <code>red-text</code>.
testString: assert($("p:eq(0)").hasClass("red-text"));
Your `h2` element should be red.
```js
assert($('h2').css('color') === 'rgb(255, 0, 0)');
```
</section>
Your `h2` element should have the class `red-text`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h2').hasClass('red-text'));
```
<div id='html-seed'>
Your first `p` element should be red.
```js
assert($('p:eq(0)').css('color') === 'rgb(255, 0, 0)');
```
Your second and third `p` elements should not be red.
```js
assert(
!($('p:eq(1)').css('color') === 'rgb(255, 0, 0)') &&
!($('p:eq(2)').css('color') === 'rgb(255, 0, 0)')
);
```
Your first `p` element should have the class `red-text`.
```js
assert($('p:eq(0)').hasClass('red-text'));
```
# --seed--
## --seed-contents--
```html
<style>
@ -81,14 +89,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -129,5 +130,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,16 +6,17 @@ videoUrl: 'https://scrimba.com/c/cB77PHW'
forumTopicId: 18313
---
## Description
<section id='description'>
Now let's start fresh and talk about CSS inheritance.
Every HTML page has a <code>body</code> element.
</section>
# --description--
## Instructions
<section id='instructions'>
We can prove that the <code>body</code> element exists here by giving it a <code>background-color</code> of black.
We can do this by adding the following to our <code>style</code> element:
Now let's start fresh and talk about CSS inheritance.
Every HTML page has a `body` element.
# --instructions--
We can prove that the `body` element exists here by giving it a `background-color` of black.
We can do this by adding the following to our `style` element:
```css
body {
@ -23,28 +24,33 @@ body {
}
```
</section>
# --hints--
## Tests
<section id='tests'>
```yml
tests:
- text: Your <code>body</code> element should have the <code>background-color</code> of black.
testString: assert($("body").css("background-color") === "rgb(0, 0, 0)");
- text: Your CSS rule should be properly formatted with both opening and closing curly brackets.
testString: assert(code.match(/<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i));
- text: Your CSS rule should end with a semi-colon.
testString: assert(code.match(/<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i));
Your `body` element should have the `background-color` of black.
```js
assert($('body').css('background-color') === 'rgb(0, 0, 0)');
```
</section>
Your CSS rule should be properly formatted with both opening and closing curly brackets.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
code.match(/<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i)
);
```
<div id='html-seed'>
Your CSS rule should end with a semi-colon.
```js
assert(
code.match(/<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -52,14 +58,7 @@ tests:
</style>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -68,5 +67,3 @@ body {
}
</style>
```
</section>

View File

@ -6,37 +6,42 @@ videoUrl: 'https://scrimba.com/c/cN66JSL'
forumTopicId: 301089
---
## Description
<section id='description'>
The last several challenges all set an element's margin or padding with pixels (<code>px</code>). Pixels are a type of length unit, which is what tells the browser how to size or space an item. In addition to <code>px</code>, CSS has a number of different length unit options that you can use.
The two main types of length units are absolute and relative. Absolute units tie to physical units of length. For example, <code>in</code> and <code>mm</code> refer to inches and millimeters, respectively. Absolute length units approximate the actual measurement on a screen, but there are some differences depending on a screen's resolution.
Relative units, such as <code>em</code> or <code>rem</code>, are relative to another length value. For example, <code>em</code> is based on the size of an element's font. If you use it to set the <code>font-size</code> property itself, it's relative to the parent's <code>font-size</code>.
<strong>Note:</strong> There are several relative unit options that are tied to the size of the viewport. They are covered in the Responsive Web Design Principles section.
</section>
# --description--
## Instructions
<section id='instructions'>
Add a <code>padding</code> property to the element with class <code>red-box</code> and set it to <code>1.5em</code>.
</section>
The last several challenges all set an element's margin or padding with pixels (`px`). Pixels are a type of length unit, which is what tells the browser how to size or space an item. In addition to `px`, CSS has a number of different length unit options that you can use.
## Tests
<section id='tests'>
The two main types of length units are absolute and relative. Absolute units tie to physical units of length. For example, `in` and `mm` refer to inches and millimeters, respectively. Absolute length units approximate the actual measurement on a screen, but there are some differences depending on a screen's resolution.
```yml
tests:
- text: Your <code>red-box</code> class should have a <code>padding</code> property.
testString: assert($('.red-box').css('padding-top') != '0px' && $('.red-box').css('padding-right') != '0px' && $('.red-box').css('padding-bottom') != '0px' && $('.red-box').css('padding-left') != '0px');
- text: Your <code>red-box</code> class should give elements 1.5em of <code>padding</code>.
testString: assert(code.match(/\.red-box\s*?{[\s\S]*padding:\s*?1\.5em/gi));
Relative units, such as `em` or `rem`, are relative to another length value. For example, `em` is based on the size of an element's font. If you use it to set the `font-size` property itself, it's relative to the parent's `font-size`.
**Note:** There are several relative unit options that are tied to the size of the viewport. They are covered in the Responsive Web Design Principles section.
# --instructions--
Add a `padding` property to the element with class `red-box` and set it to `1.5em`.
# --hints--
Your `red-box` class should have a `padding` property.
```js
assert(
$('.red-box').css('padding-top') != '0px' &&
$('.red-box').css('padding-right') != '0px' &&
$('.red-box').css('padding-bottom') != '0px' &&
$('.red-box').css('padding-left') != '0px'
);
```
</section>
Your `red-box` class should give elements 1.5em of `padding`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/\.red-box\s*?{[\s\S]*padding:\s*?1\.5em/gi));
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<style>
@ -76,14 +81,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -122,5 +120,3 @@ tests:
<h5 class="box green-box">padding</h5>
</div>
```
</section>

View File

@ -6,9 +6,10 @@ videoUrl: 'https://scrimba.com/c/c2MvDtV'
forumTopicId: 18337
---
## Description
<section id='description'>
# --description--
Classes are reusable styles that can be added to HTML elements.
Here's an example CSS class declaration:
```html
@ -19,40 +20,43 @@ Here's an example CSS class declaration:
</style>
```
You can see that we've created a CSS class called <code>blue-text</code> within the <code>&#60;style&#62;</code> tag.
You can apply a class to an HTML element like this:
<code>&#60;h2 class="blue-text"&#62;CatPhotoApp&#60;/h2&#62;</code>
Note that in your CSS <code>style</code> element, class names start with a period. In your HTML elements' class attribute, the class name does not include the period.
</section>
You can see that we've created a CSS class called `blue-text` within the `<style>` tag. You can apply a class to an HTML element like this: `<h2 class="blue-text">CatPhotoApp</h2>` Note that in your CSS `style` element, class names start with a period. In your HTML elements' class attribute, the class name does not include the period.
## Instructions
<section id='instructions'>
Inside your <code>style</code> element, change the <code>h2</code> selector to <code>.red-text</code> and update the color's value from <code>blue</code> to <code>red</code>.
Give your <code>h2</code> element the <code>class</code> attribute with a value of <code>'red-text'</code>.
</section>
# --instructions--
## Tests
<section id='tests'>
Inside your `style` element, change the `h2` selector to `.red-text` and update the color's value from `blue` to `red`.
```yml
tests:
- text: Your <code>h2</code> element should be red.
testString: assert($("h2").css("color") === "rgb(255, 0, 0)");
- text: Your <code>h2</code> element should have the class <code>red-text</code>.
testString: assert($("h2").hasClass("red-text"));
- text: Your stylesheet should declare a <code>red-text</code> class and have its color set to red.
testString: assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g));
- text: You should not use inline style declarations like <code>style="color&#58; red"</code> in your <code>h2</code> element.
testString: assert($("h2").attr("style") === undefined);
Give your `h2` element the `class` attribute with a value of `'red-text'`.
# --hints--
Your `h2` element should be red.
```js
assert($('h2').css('color') === 'rgb(255, 0, 0)');
```
</section>
Your `h2` element should have the class `red-text`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('h2').hasClass('red-text'));
```
<div id='html-seed'>
Your stylesheet should declare a `red-text` class and have its color set to red.
```js
assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g));
```
You should not use inline style declarations like `style="color: red"` in your `h2` element.
```js
assert($('h2').attr('style') === undefined);
```
# --seed--
## --seed-contents--
```html
<style>
@ -94,14 +98,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -142,5 +139,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,45 +6,65 @@ videoUrl: 'https://scrimba.com/c/cM989ck'
forumTopicId: 301090
---
## Description
<section id='description'>
# --description--
After you create your variable, you can assign its value to other CSS properties by referencing the name you gave it.
```css
background: var(--penguin-skin);
```
This will change the background of whatever element you are targeting to gray because that is the value of the <code>--penguin-skin</code> variable.
Note that styles will not be applied unless the variable names are an exact match.
</section>
This will change the background of whatever element you are targeting to gray because that is the value of the `--penguin-skin` variable. Note that styles will not be applied unless the variable names are an exact match.
## Instructions
<section id='instructions'>
Apply the <code>--penguin-skin</code> variable to the <code>background</code> property of the <code>penguin-top</code>, <code>penguin-bottom</code>, <code>right-hand</code> and <code>left-hand</code> classes.
</section>
# --instructions--
## Tests
<section id='tests'>
Apply the `--penguin-skin` variable to the `background` property of the `penguin-top`, `penguin-bottom`, `right-hand` and `left-hand` classes.
```yml
tests:
- text: The <code>--penguin-skin</code> variable should be applied to the <code>background</code> property of the <code>penguin-top</code> class.
testString: assert(code.match(/.penguin-top\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.penguin-bottom\s{/gi));
- text: The <code>--penguin-skin</code> variable should be applied to the <code>background</code> property of the <code>penguin-bottom</code> class.
testString: assert(code.match(/.penguin-bottom\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.right-hand\s{/gi));
- text: The <code>--penguin-skin</code> variable should be applied to the <code>background</code> property of the <code>right-hand</code> class.
testString: assert(code.match(/.right-hand\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.left-hand\s{/gi));
- text: The <code>--penguin-skin</code> variable should be applied to the <code>background</code> property of the <code>left-hand</code> class.
testString: assert(code.match(/.left-hand\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}/gi));
# --hints--
The `--penguin-skin` variable should be applied to the `background` property of the `penguin-top` class.
```js
assert(
code.match(
/.penguin-top\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.penguin-bottom\s{/gi
)
);
```
</section>
The `--penguin-skin` variable should be applied to the `background` property of the `penguin-bottom` class.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
code.match(
/.penguin-bottom\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.right-hand\s{/gi
)
);
```
<div id='html-seed'>
The `--penguin-skin` variable should be applied to the `background` property of the `right-hand` class.
```js
assert(
code.match(
/.right-hand\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.left-hand\s{/gi
)
);
```
The `--penguin-skin` variable should be applied to the `background` property of the `left-hand` class.
```js
assert(
code.match(
/.left-hand\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -259,18 +279,8 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>.penguin-top {background: var(--penguin-skin);} .penguin-bottom {background: var(--penguin-skin);} .right-hand {background: var(--penguin-skin);} .left-hand {background: var(--penguin-skin);}</style>
```
</section>

View File

@ -6,35 +6,41 @@ videoUrl: 'https://scrimba.com/c/cWmL8UP'
forumTopicId: 301091
---
## Description
<section id='description'>
# --description--
CSS Variables can simplify the way you use media queries.
For instance, when your screen is smaller or larger than your media query break point, you can change the value of a variable, and it will apply its style wherever it is used.
</section>
## Instructions
<section id='instructions'>
In the <code>:root</code> selector of the <code>media query</code>, change it so <code>--penguin-size</code> is redefined and given a value of <code>200px</code>. Also, redefine <code>--penguin-skin</code> and give it a value of <code>black</code>. Then resize the preview to see this change in action.
</section>
# --instructions--
## Tests
<section id='tests'>
In the `:root` selector of the `media query`, change it so `--penguin-size` is redefined and given a value of `200px`. Also, redefine `--penguin-skin` and give it a value of `black`. Then resize the preview to see this change in action.
```yml
tests:
- text: <code>:root</code> should reassign the <code>--penguin-size</code> variable to <code>200px</code>.
testString: assert(code.match(/media\s*?\(\s*?max-width\s*?:\s*?350px\s*?\)\s*?{[\s\S]*:root\s*?{[\s\S]*--penguin-size\s*?:\s*?200px\s*?;[\s\S]*}[\s\S]*}/gi));
- text: <code>:root</code> should reassign the <code>--penguin-skin</code> variable to <code>black</code>.
testString: assert(code.match(/media\s*?\(\s*?max-width\s*?:\s*?350px\s*?\)\s*?{[\s\S]*:root\s*?{[\s\S]*--penguin-skin\s*?:\s*?black\s*?;[\s\S]*}[\s\S]*}/gi));
# --hints--
`:root` should reassign the `--penguin-size` variable to `200px`.
```js
assert(
code.match(
/media\s*?\(\s*?max-width\s*?:\s*?350px\s*?\)\s*?{[\s\S]*:root\s*?{[\s\S]*--penguin-size\s*?:\s*?200px\s*?;[\s\S]*}[\s\S]*}/gi
)
);
```
</section>
`:root` should reassign the `--penguin-skin` variable to `black`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
code.match(
/media\s*?\(\s*?max-width\s*?:\s*?350px\s*?\)\s*?{[\s\S]*:root\s*?{[\s\S]*--penguin-skin\s*?:\s*?black\s*?;[\s\S]*}[\s\S]*}/gi
)
);
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<style>
@ -267,18 +273,8 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>@media (max-width: 350px) {:root {--penguin-size: 200px; --penguin-skin: black;}}</style>
```
</section>

View File

@ -6,49 +6,73 @@ videoUrl: 'https://scrimba.com/c/cRkpKAm'
forumTopicId: 18338
---
## Description
<section id='description'>
# --description--
Many people feel overwhelmed by the possibilities of more than 16 million colors. And it's difficult to remember hex code. Fortunately, you can shorten it.
For example, red's hex code <code>#FF0000</code> can be shortened to <code>#F00</code>. This shortened form gives one digit for red, one digit for green, and one digit for blue.
This reduces the total number of possible colors to around 4,000. But browsers will interpret <code>#FF0000</code> and <code>#F00</code> as exactly the same color.
</section>
## Instructions
<section id='instructions'>
For example, red's hex code `#FF0000` can be shortened to `#F00`. This shortened form gives one digit for red, one digit for green, and one digit for blue.
This reduces the total number of possible colors to around 4,000. But browsers will interpret `#FF0000` and `#F00` as exactly the same color.
# --instructions--
Go ahead, try using the abbreviated hex codes to color the correct elements.
<table class='table table-striped'><tr><th>Color</th><th>Short Hex Code</th></tr><tr><td>Cyan</td><td><code>#0FF</code></td></tr><tr><td>Green</td><td><code>#0F0</code></td></tr><tr><td>Red</td><td><code>#F00</code></td></tr><tr><td>Fuchsia</td><td><code>#F0F</code></td></tr></table>
</section>
## Tests
<section id='tests'>
<table class='table table-striped'><tbody><tr><th>Color</th><th>Short Hex Code</th></tr><tr><td>Cyan</td><td><code>#0FF</code></td></tr><tr><td>Green</td><td><code>#0F0</code></td></tr><tr><td>Red</td><td><code>#F00</code></td></tr><tr><td>Fuchsia</td><td><code>#F0F</code></td></tr></tbody></table>
```yml
tests:
- text: Your <code>h1</code> element with the text <code>I am red!</code> should be given the <code>color</code> red.
testString: assert($('.red-text').css('color') === 'rgb(255, 0, 0)');
- text: The abbreviated <code>hex code</code> for the color red should be used instead of the hex code <code>#FF0000</code>.
testString: assert(code.match(/\.red-text\s*?{\s*?color:\s*?#F00\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am green!</code> should be given the <code>color</code> green.
testString: assert($('.green-text').css('color') === 'rgb(0, 255, 0)');
- text: The abbreviated <code>hex code</code> for the color green should be used instead of the hex code <code>#00FF00</code>.
testString: assert(code.match(/\.green-text\s*?{\s*?color:\s*?#0F0\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am cyan!</code> should be given the <code>color</code> cyan.
testString: assert($('.cyan-text').css('color') === 'rgb(0, 255, 255)');
- text: The abbreviated <code>hex code</code> for the color cyan should be used instead of the hex code <code>#00FFFF</code>.
testString: assert(code.match(/\.cyan-text\s*?{\s*?color:\s*?#0FF\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am fuchsia!</code> should be given the <code>color</code> fuchsia.
testString: assert($('.fuchsia-text').css('color') === 'rgb(255, 0, 255)');
- text: The abbreviated <code>hex code</code> for the color fuchsia should be used instead of the hex code <code>#FF00FF</code>.
testString: assert(code.match(/\.fuchsia-text\s*?{\s*?color:\s*?#F0F\s*?;\s*?}/gi));
# --hints--
Your `h1` element with the text `I am red!` should be given the `color` red.
```js
assert($('.red-text').css('color') === 'rgb(255, 0, 0)');
```
</section>
The abbreviated `hex code` for the color red should be used instead of the hex code `#FF0000`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/\.red-text\s*?{\s*?color:\s*?#F00\s*?;\s*?}/gi));
```
<div id='html-seed'>
Your `h1` element with the text `I am green!` should be given the `color` green.
```js
assert($('.green-text').css('color') === 'rgb(0, 255, 0)');
```
The abbreviated `hex code` for the color green should be used instead of the hex code `#00FF00`.
```js
assert(code.match(/\.green-text\s*?{\s*?color:\s*?#0F0\s*?;\s*?}/gi));
```
Your `h1` element with the text `I am cyan!` should be given the `color` cyan.
```js
assert($('.cyan-text').css('color') === 'rgb(0, 255, 255)');
```
The abbreviated `hex code` for the color cyan should be used instead of the hex code `#00FFFF`.
```js
assert(code.match(/\.cyan-text\s*?{\s*?color:\s*?#0FF\s*?;\s*?}/gi));
```
Your `h1` element with the text `I am fuchsia!` should be given the `color` fuchsia.
```js
assert($('.fuchsia-text').css('color') === 'rgb(255, 0, 255)');
```
The abbreviated `hex code` for the color fuchsia should be used instead of the hex code `#FF00FF`.
```js
assert(code.match(/\.fuchsia-text\s*?{\s*?color:\s*?#F0F\s*?;\s*?}/gi));
```
# --seed--
## --seed-contents--
```html
<style>
@ -75,14 +99,7 @@ tests:
<h1 class="green-text">I am green!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -108,5 +125,3 @@ tests:
<h1 class="green-text">I am green!</h1>
```
</section>

View File

@ -6,11 +6,13 @@ videoUrl: 'https://scrimba.com/c/cakyZfL'
forumTopicId: 18339
---
## Description
<section id='description'>
One cool thing about <code>id</code> attributes is that, like classes, you can style them using CSS.
However, an <code>id</code> is not reusable and should only be applied to one element. An <code>id</code> also has a higher specificity (importance) than a class so if both are applied to the same element and have conflicting styles, the styles of the <code>id</code> will be applied.
Here's an example of how you can take your element with the <code>id</code> attribute of <code>cat-photo-element</code> and give it the background color of green. In your <code>style</code> element:
# --description--
One cool thing about `id` attributes is that, like classes, you can style them using CSS.
However, an `id` is not reusable and should only be applied to one element. An `id` also has a higher specificity (importance) than a class so if both are applied to the same element and have conflicting styles, the styles of the `id` will be applied.
Here's an example of how you can take your element with the `id` attribute of `cat-photo-element` and give it the background color of green. In your `style` element:
```css
#cat-photo-element {
@ -18,36 +20,44 @@ Here's an example of how you can take your element with the <code>id</code> attr
}
```
Note that inside your <code>style</code> element, you always reference classes by putting a <code>.</code> in front of their names. You always reference ids by putting a <code>#</code> in front of their names.
</section>
Note that inside your `style` element, you always reference classes by putting a `.` in front of their names. You always reference ids by putting a `#` in front of their names.
## Instructions
<section id='instructions'>
Try giving your form, which now has the <code>id</code> attribute of <code>cat-photo-form</code>, a green background.
</section>
# --instructions--
## Tests
<section id='tests'>
Try giving your form, which now has the `id` attribute of `cat-photo-form`, a green background.
```yml
tests:
- text: Your <code>form</code> element should have the id of <code>cat-photo-form</code>.
testString: assert($("form").attr("id") === "cat-photo-form");
- text: Your <code>form</code> element should have the <code>background-color</code> of green.
testString: assert($("#cat-photo-form").css("background-color") === "rgb(0, 128, 0)");
- text: Your <code>form</code> element should have an <code>id</code> attribute.
testString: assert(code.match(/<form.*cat-photo-form.*>/gi) && code.match(/<form.*cat-photo-form.*>/gi).length > 0);
- text: You should not give your <code>form</code> any <code>class</code> or <code>style</code> attributes.
testString: assert(!code.match(/<form.*style.*>/gi) && !code.match(/<form.*class.*>/gi));
# --hints--
Your `form` element should have the id of `cat-photo-form`.
```js
assert($('form').attr('id') === 'cat-photo-form');
```
</section>
Your `form` element should have the `background-color` of green.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('#cat-photo-form').css('background-color') === 'rgb(0, 128, 0)');
```
<div id='html-seed'>
Your `form` element should have an `id` attribute.
```js
assert(
code.match(/<form.*cat-photo-form.*>/gi) &&
code.match(/<form.*cat-photo-form.*>/gi).length > 0
);
```
You should not give your `form` any `class` or `style` attributes.
```js
assert(!code.match(/<form.*style.*>/gi) && !code.match(/<form.*class.*>/gi));
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -114,14 +124,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -191,5 +194,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,11 +6,13 @@ videoUrl: 'https://scrimba.com/c/cnpymfJ'
forumTopicId: 301092
---
## Description
<section id='description'>
You have been adding <code>id</code> or <code>class</code> attributes to elements that you wish to specifically style. These are known as ID and class selectors. There are other CSS Selectors you can use to select custom groups of elements to style.
# --description--
You have been adding `id` or `class` attributes to elements that you wish to specifically style. These are known as ID and class selectors. There are other CSS Selectors you can use to select custom groups of elements to style.
Let's bring out CatPhotoApp again to practice using CSS Selectors.
For this challenge, you will use the <code>[attr=value]</code> attribute selector to style the checkboxes in CatPhotoApp. This selector matches and styles elements with a specific attribute value. For example, the below code changes the margins of all elements with the attribute <code>type</code> and a corresponding value of <code>radio</code>:
For this challenge, you will use the `[attr=value]` attribute selector to style the checkboxes in CatPhotoApp. This selector matches and styles elements with a specific attribute value. For example, the below code changes the margins of all elements with the attribute `type` and a corresponding value of `radio`:
```css
[type='radio'] {
@ -18,33 +20,57 @@ For this challenge, you will use the <code>[attr=value]</code> attribute selecto
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Using the <code>type</code> attribute selector, try to give the checkboxes in CatPhotoApp a top margin of 10px and a bottom margin of 15px.
</section>
Using the `type` attribute selector, try to give the checkboxes in CatPhotoApp a top margin of 10px and a bottom margin of 15px.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: The <code>type</code> attribute selector should be used to select the checkboxes.
testString: assert(code.match(/<style>[\s\S]*?\[\s*?type\s*?=\s*?("|')checkbox\1\s*?\]\s*?{[\s\S]*?}[\s\S]*?<\/style>/gi));
- text: The top margins of the checkboxes should be 10px.
testString: assert((function() {var count=0; $("[type='checkbox']").each(function() { if($(this).css('marginTop') === '10px') {count++;}});return (count===3)}()));
- text: The bottom margins of the checkboxes should be 15px.
testString: assert((function() {var count=0; $("[type='checkbox']").each(function() { if($(this).css('marginBottom') === '15px') {count++;}});return (count===3)}()));
The `type` attribute selector should be used to select the checkboxes.
```js
assert(
code.match(
/<style>[\s\S]*?\[\s*?type\s*?=\s*?("|')checkbox\1\s*?\]\s*?{[\s\S]*?}[\s\S]*?<\/style>/gi
)
);
```
</section>
The top margins of the checkboxes should be 10px.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
(function () {
var count = 0;
$("[type='checkbox']").each(function () {
if ($(this).css('marginTop') === '10px') {
count++;
}
});
return count === 3;
})()
);
```
<div id='html-seed'>
The bottom margins of the checkboxes should be 15px.
```js
assert(
(function () {
var count = 0;
$("[type='checkbox']").each(function () {
if ($(this).css('marginBottom') === '15px') {
count++;
}
});
return count === 3;
})()
);
```
# --seed--
## --seed-contents--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -111,14 +137,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
@ -188,5 +207,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,43 +6,59 @@ videoUrl: 'https://scrimba.com/c/cnpybAd'
forumTopicId: 18345
---
## Description
<section id='description'>
Let's try this again, but with <code>margin</code> this time.
Instead of specifying an element's <code>margin-top</code>, <code>margin-right</code>, <code>margin-bottom</code>, and <code>margin-left</code> properties individually, you can specify them all in one line, like this:
<code>margin: 10px 20px 10px 20px;</code>
# --description--
Let's try this again, but with `margin` this time.
Instead of specifying an element's `margin-top`, `margin-right`, `margin-bottom`, and `margin-left` properties individually, you can specify them all in one line, like this:
`margin: 10px 20px 10px 20px;`
These four values work like a clock: top, right, bottom, left, and will produce the exact same result as using the side-specific margin instructions.
</section>
## Instructions
<section id='instructions'>
Use Clockwise Notation to give the element with the <code>blue-box</code> class a margin of <code>40px</code> on its top and left side, but only <code>20px</code> on its bottom and right side.
</section>
# --instructions--
## Tests
<section id='tests'>
Use Clockwise Notation to give the element with the `blue-box` class a margin of `40px` on its top and left side, but only `20px` on its bottom and right side.
```yml
tests:
- text: Your <code>blue-box</code> class should give the top of elements <code>40px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-top") === "40px");
- text: Your <code>blue-box</code> class should give the right of elements <code>20px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-right") === "20px");
- text: Your <code>blue-box</code> class should give the bottom of elements <code>20px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-bottom") === "20px");
- text: Your <code>blue-box</code> class should give the left of elements <code>40px</code> of <code>margin</code>.
testString: assert($(".blue-box").css("margin-left") === "40px");
- text: You should use the clockwise notation to set the margin of <code>blue-box</code> class.
testString: assert(/\.blue-box\s*{[\s\S]*margin[\s]*:\s*\d+px\s+\d+px\s+\d+px\s+\d+px(;\s*[^}]+\s*}|;?\s*})/.test(__helpers.removeCssComments($('style').text())));
# --hints--
Your `blue-box` class should give the top of elements `40px` of `margin`.
```js
assert($('.blue-box').css('margin-top') === '40px');
```
</section>
Your `blue-box` class should give the right of elements `20px` of `margin`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('.blue-box').css('margin-right') === '20px');
```
<div id='html-seed'>
Your `blue-box` class should give the bottom of elements `20px` of `margin`.
```js
assert($('.blue-box').css('margin-bottom') === '20px');
```
Your `blue-box` class should give the left of elements `40px` of `margin`.
```js
assert($('.blue-box').css('margin-left') === '40px');
```
You should use the clockwise notation to set the margin of `blue-box` class.
```js
assert(
/\.blue-box\s*{[\s\S]*margin[\s]*:\s*\d+px\s+\d+px\s+\d+px\s+\d+px(;\s*[^}]+\s*}|;?\s*})/.test(
__helpers.removeCssComments($('style').text())
)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -82,12 +98,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -127,5 +138,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,42 +6,57 @@ videoUrl: 'https://scrimba.com/c/cB7mBS9'
forumTopicId: 18346
---
## Description
<section id='description'>
Instead of specifying an element's <code>padding-top</code>, <code>padding-right</code>, <code>padding-bottom</code>, and <code>padding-left</code> properties individually, you can specify them all in one line, like this:
<code>padding: 10px 20px 10px 20px;</code>
# --description--
Instead of specifying an element's `padding-top`, `padding-right`, `padding-bottom`, and `padding-left` properties individually, you can specify them all in one line, like this:
`padding: 10px 20px 10px 20px;`
These four values work like a clock: top, right, bottom, left, and will produce the exact same result as using the side-specific padding instructions.
</section>
## Instructions
<section id='instructions'>
Use Clockwise Notation to give the ".blue-box" class a <code>padding</code> of <code>40px</code> on its top and left side, but only <code>20px</code> on its bottom and right side.
</section>
# --instructions--
## Tests
<section id='tests'>
Use Clockwise Notation to give the ".blue-box" class a `padding` of `40px` on its top and left side, but only `20px` on its bottom and right side.
```yml
tests:
- text: Your <code>blue-box</code> class should give the top of elements <code>40px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-top") === "40px");
- text: Your <code>blue-box</code> class should give the right of elements <code>20px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-right") === "20px");
- text: Your <code>blue-box</code> class should give the bottom of elements <code>20px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-bottom") === "20px");
- text: Your <code>blue-box</code> class should give the left of elements <code>40px</code> of <code>padding</code>.
testString: assert($(".blue-box").css("padding-left") === "40px");
- text: You should use the clockwise notation to set the padding of <code>blue-box</code> class.
testString: assert(/\.blue-box\s*{[\s\S]*padding[\s]*:\s*\d+px\s+\d+px\s+\d+px\s+\d+px(;\s*[^}]+\s*}|;?\s*})/.test(__helpers.removeCssComments($('style').text())));
# --hints--
Your `blue-box` class should give the top of elements `40px` of `padding`.
```js
assert($('.blue-box').css('padding-top') === '40px');
```
</section>
Your `blue-box` class should give the right of elements `20px` of `padding`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('.blue-box').css('padding-right') === '20px');
```
<div id='html-seed'>
Your `blue-box` class should give the bottom of elements `20px` of `padding`.
```js
assert($('.blue-box').css('padding-bottom') === '20px');
```
Your `blue-box` class should give the left of elements `40px` of `padding`.
```js
assert($('.blue-box').css('padding-left') === '40px');
```
You should use the clockwise notation to set the padding of `blue-box` class.
```js
assert(
/\.blue-box\s*{[\s\S]*padding[\s]*:\s*\d+px\s+\d+px\s+\d+px\s+\d+px(;\s*[^}]+\s*}|;?\s*})/.test(
__helpers.removeCssComments($('style').text())
)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -81,14 +96,7 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -128,5 +136,3 @@ tests:
<h5 class="box blue-box">padding</h5>
</div>
```
</section>

View File

@ -6,19 +6,22 @@ videoUrl: 'https://scrimba.com/c/cJKMBT2'
forumTopicId: 18349
---
## Description
<section id='description'>
# --description--
With CSS, there are hundreds of CSS properties that you can use to change the way an element looks on your page.
When you entered <code>&#60;h2 style="color: red;"&#62;CatPhotoApp&#60;/h2&#62;</code>, you were styling that individual <code>h2</code> element with inline CSS, which stands for Cascading Style Sheets.
When you entered `<h2 style="color: red;">CatPhotoApp</h2>`, you were styling that individual `h2` element with inline CSS, which stands for Cascading Style Sheets.
That's one way to specify the style of an element, but there's a better way to apply CSS.
At the top of your code, create a <code>style</code> block like this:
At the top of your code, create a `style` block like this:
```html
<style>
</style>
```
Inside that style block, you can create a <dfn>CSS selector</dfn> for all <code>h2</code> elements. For example, if you wanted all <code>h2</code> elements to be red, you would add a style rule that looks like this:
Inside that style block, you can create a <dfn>CSS selector</dfn> for all `h2` elements. For example, if you wanted all `h2` elements to be red, you would add a style rule that looks like this:
```html
<style>
@ -28,38 +31,55 @@ Inside that style block, you can create a <dfn>CSS selector</dfn> for all <code>
</style>
```
Note that it's important to have both opening and closing curly braces (<code>{</code> and <code>}</code>) around each element's style rule(s). You also need to make sure that your element's style definition is between the opening and closing style tags. Finally, be sure to add a semicolon to the end of each of your element's style rules.
</section>
Note that it's important to have both opening and closing curly braces (`{` and `}`) around each element's style rule(s). You also need to make sure that your element's style definition is between the opening and closing style tags. Finally, be sure to add a semicolon to the end of each of your element's style rules.
## Instructions
<section id='instructions'>
Delete your <code>h2</code> element's style attribute, and instead create a CSS <code>style</code> block. Add the necessary CSS to turn all <code>h2</code> elements blue.
</section>
# --instructions--
## Tests
<section id='tests'>
Delete your `h2` element's style attribute, and instead create a CSS `style` block. Add the necessary CSS to turn all `h2` elements blue.
```yml
tests:
- text: The style attribute should be removed from your <code>h2</code> element.
testString: assert(!$("h2").attr("style"));
- text: You should create a <code>style</code> element.
testString: assert($("style") && $("style").length >= 1);
- text: Your <code>h2</code> element should be blue.
testString: assert($("h2").css("color") === "rgb(0, 0, 255)");
- text: Your stylesheet <code>h2</code> declaration should be valid with a semicolon and closing brace.
testString: assert(code.match(/h2\s*\{\s*color\s*:.*;\s*\}/g));
- text: All your <code>style</code> elements should be valid and have closing tags.
testString: assert(code.match(/<\/style>/g) && code.match(/<\/style>/g).length === (code.match(/<style((\s)*((type|media|scoped|title|disabled)="[^"]*")?(\s)*)*>/g) || []).length);
# --hints--
The style attribute should be removed from your `h2` element.
```js
assert(!$('h2').attr('style'));
```
</section>
You should create a `style` element.
## Challenge Seed
<section id='challengeSeed'>
```js
assert($('style') && $('style').length >= 1);
```
<div id='html-seed'>
Your `h2` element should be blue.
```js
assert($('h2').css('color') === 'rgb(0, 0, 255)');
```
Your stylesheet `h2` declaration should be valid with a semicolon and closing brace.
```js
assert(code.match(/h2\s*\{\s*color\s*:.*;\s*\}/g));
```
All your `style` elements should be valid and have closing tags.
```js
assert(
code.match(/<\/style>/g) &&
code.match(/<\/style>/g).length ===
(
code.match(
/<style((\s)*((type|media|scoped|title|disabled)="[^"]*")?(\s)*)*>/g
) || []
).length
);
```
# --seed--
## --seed-contents--
```html
<h2 style="color: red;">CatPhotoApp</h2>
@ -95,14 +115,7 @@ tests:
</main>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -142,5 +155,3 @@ tests:
</form>
</main>
```
</section>

View File

@ -6,37 +6,45 @@ videoUrl: 'https://scrimba.com/c/c6bDECm'
forumTopicId: 301093
---
## Description
<section id='description'>
# --description--
<dfn>CSS Variables</dfn> are a powerful way to change many CSS style properties at once by changing only one value.
Follow the instructions below to see how changing just three values can change the styling of many elements.
</section>
## Instructions
<section id='instructions'>
In the <code>penguin</code> class, change the <code>black</code> value to <code>gray</code>, the <code>gray</code> value to <code>white</code>, and the <code>yellow</code> value to <code>orange</code>.
</section>
# --instructions--
## Tests
<section id='tests'>
In the `penguin` class, change the `black` value to `gray`, the `gray` value to `white`, and the `yellow` value to `orange`.
```yml
tests:
- text: <code>penguin</code> class should declare the <code>--penguin-skin</code> variable and assign it to <code>gray</code>.
testString: assert(code.match(/.penguin\s*?{[\s\S]*--penguin-skin\s*?:\s*?gray\s*?;[\s\S]*}/gi));
- text: <code>penguin</code> class should declare the <code>--penguin-belly</code> variable and assign it to <code>white</code>.
testString: assert(code.match(/.penguin\s*?{[\s\S]*--penguin-belly\s*?:\s*?white\s*?;[\s\S]*}/gi));
- text: <code>penguin</code> class should declare the <code>--penguin-beak</code> variable and assign it to <code>orange</code>.
testString: assert(code.match(/.penguin\s*?{[\s\S]*--penguin-beak\s*?:\s*?orange\s*?;[\s\S]*}/gi));
# --hints--
`penguin` class should declare the `--penguin-skin` variable and assign it to `gray`.
```js
assert(
code.match(/.penguin\s*?{[\s\S]*--penguin-skin\s*?:\s*?gray\s*?;[\s\S]*}/gi)
);
```
</section>
`penguin` class should declare the `--penguin-belly` variable and assign it to `white`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
code.match(/.penguin\s*?{[\s\S]*--penguin-belly\s*?:\s*?white\s*?;[\s\S]*}/gi)
);
```
<div id='html-seed'>
`penguin` class should declare the `--penguin-beak` variable and assign it to `orange`.
```js
assert(
code.match(/.penguin\s*?{[\s\S]*--penguin-beak\s*?:\s*?orange\s*?;[\s\S]*}/gi)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -241,18 +249,8 @@ tests:
</div>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>.penguin {--penguin-skin: gray; --penguin-belly: white; --penguin-beak: orange;}</style>
```
</section>

View File

@ -6,11 +6,13 @@ videoUrl: 'https://scrimba.com/c/c8W9mHM'
forumTopicId: 18350
---
## Description
<section id='description'>
# --description--
Did you know there are other ways to represent colors in CSS? One of these ways is called hexadecimal code, or hex code for short.
We usually use <dfn>decimals</dfn>, or base 10 numbers, which use the symbols 0 to 9 for each digit. <dfn>Hexadecimals</dfn> (or <dfn>hex</dfn>) are base 16 numbers. This means it uses sixteen distinct symbols. Like decimals, the symbols 0-9 represent the values zero to nine. Then A,B,C,D,E,F represent the values ten to fifteen. Altogether, 0 to F can represent a digit in hexadecimal, giving us 16 total possible values. You can find more information about <a target='_blank' href='https://en.wikipedia.org/wiki/Hexadecimal'>hexadecimal numbers here</a>.
In CSS, we can use 6 hexadecimal digits to represent colors, two each for the red (R), green (G), and blue (B) components. For example, <code>#000000</code> is black and is also the lowest possible value. You can find more information about the <a target='_blank' href='https://en.wikipedia.org/wiki/RGB_color_model'>RGB color system here</a>.
We usually use <dfn>decimals</dfn>, or base 10 numbers, which use the symbols 0 to 9 for each digit. <dfn>Hexadecimals</dfn> (or <dfn>hex</dfn>) are base 16 numbers. This means it uses sixteen distinct symbols. Like decimals, the symbols 0-9 represent the values zero to nine. Then A,B,C,D,E,F represent the values ten to fifteen. Altogether, 0 to F can represent a digit in hexadecimal, giving us 16 total possible values. You can find more information about [hexadecimal numbers here](https://en.wikipedia.org/wiki/Hexadecimal).
In CSS, we can use 6 hexadecimal digits to represent colors, two each for the red (R), green (G), and blue (B) components. For example, `#000000` is black and is also the lowest possible value. You can find more information about the [RGB color system here](https://en.wikipedia.org/wiki/RGB_color_model).
```css
body {
@ -18,31 +20,31 @@ body {
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Replace the word <code>black</code> in our <code>body</code> element's background-color with its hex code representation, <code>#000000</code>.
</section>
Replace the word `black` in our `body` element's background-color with its hex code representation, `#000000`.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your <code>body</code> element should have the background-color of black.
testString: assert($("body").css("background-color") === "rgb(0, 0, 0)");
- text: The <code>hex code</code> for the color black should be used instead of the word <code>black</code>.
testString: assert(code.match(/body\s*{(([\s\S]*;\s*?)|\s*?)background.*\s*:\s*?#000(000)?((\s*})|(;[\s\S]*?}))/gi));
Your `body` element should have the background-color of black.
```js
assert($('body').css('background-color') === 'rgb(0, 0, 0)');
```
</section>
The `hex code` for the color black should be used instead of the word `black`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
code.match(
/body\s*{(([\s\S]*;\s*?)|\s*?)background.*\s*:\s*?#000(000)?((\s*})|(;[\s\S]*?}))/gi
)
);
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<style>
@ -52,14 +54,7 @@ tests:
</style>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -68,5 +63,3 @@ tests:
}
</style>
```
</section>

View File

@ -6,51 +6,77 @@ videoUrl: 'https://scrimba.com/c/cK89PhP'
forumTopicId: 18359
---
## Description
<section id='description'>
# --description--
To review, hex codes use 6 hexadecimal digits to represent colors, two each for red (R), green (G), and blue (B) components.
From these three pure colors (red, green, and blue), we can vary the amounts of each to create over 16 million other colors!
For example, orange is pure red, mixed with some green, and no blue. In hex code, this translates to being <code>#FFA500</code>.
The digit <code>0</code> is the lowest number in hex code, and represents a complete absence of color.
The digit <code>F</code> is the highest number in hex code, and represents the maximum possible brightness.
</section>
## Instructions
<section id='instructions'>
Replace the color words in our <code>style</code> element with their correct hex codes.
<table class='table table-striped'><tr><th>Color</th><th>Hex Code</th></tr><tr><td>Dodger Blue</td><td><code>#1E90FF</code></td></tr><tr><td>Green</td><td><code>#00FF00</code></td></tr><tr><td>Orange</td><td><code>#FFA500</code></td></tr><tr><td>Red</td><td><code>#FF0000</code></td></tr></table>
</section>
For example, orange is pure red, mixed with some green, and no blue. In hex code, this translates to being `#FFA500`.
## Tests
<section id='tests'>
The digit `0` is the lowest number in hex code, and represents a complete absence of color.
```yml
tests:
- text: Your <code>h1</code> element with the text <code>I am red!</code> should be given the <code>color</code> red.
testString: assert($('.red-text').css('color') === 'rgb(255, 0, 0)');
- text: The <code>hex code</code> for the color red should be used instead of the word <code>red</code>.
testString: assert(code.match(/\.red-text\s*?{\s*?color:\s*?(#FF0000|#F00)\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am green!</code> should be given the <code>color</code> green.
testString: assert($('.green-text').css('color') === 'rgb(0, 255, 0)');
- text: The <code>hex code</code> for the color green should be used instead of the word <code>green</code>.
testString: assert(code.match(/\.green-text\s*?{\s*?color:\s*?(#00FF00|#0F0)\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am dodger blue!</code> should be given the <code>color</code> dodger blue.
testString: assert($('.dodger-blue-text').css('color') === 'rgb(30, 144, 255)');
- text: The <code>hex code</code> for the color dodger blue should be used instead of the word <code>dodgerblue</code>.
testString: assert(code.match(/\.dodger-blue-text\s*?{\s*?color:\s*?#1E90FF\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am orange!</code> should be given the <code>color</code> orange.
testString: assert($('.orange-text').css('color') === 'rgb(255, 165, 0)');
- text: The <code>hex code</code> for the color orange should be used instead of the word <code>orange</code>.
testString: assert(code.match(/\.orange-text\s*?{\s*?color:\s*?#FFA500\s*?;\s*?}/gi));
The digit `F` is the highest number in hex code, and represents the maximum possible brightness.
# --instructions--
Replace the color words in our `style` element with their correct hex codes.
<table class='table table-striped'><tbody><tr><th>Color</th><th>Hex Code</th></tr><tr><td>Dodger Blue</td><td><code>#1E90FF</code></td></tr><tr><td>Green</td><td><code>#00FF00</code></td></tr><tr><td>Orange</td><td><code>#FFA500</code></td></tr><tr><td>Red</td><td><code>#FF0000</code></td></tr></tbody></table>
# --hints--
Your `h1` element with the text `I am red!` should be given the `color` red.
```js
assert($('.red-text').css('color') === 'rgb(255, 0, 0)');
```
</section>
The `hex code` for the color red should be used instead of the word `red`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/\.red-text\s*?{\s*?color:\s*?(#FF0000|#F00)\s*?;\s*?}/gi));
```
<div id='html-seed'>
Your `h1` element with the text `I am green!` should be given the `color` green.
```js
assert($('.green-text').css('color') === 'rgb(0, 255, 0)');
```
The `hex code` for the color green should be used instead of the word `green`.
```js
assert(code.match(/\.green-text\s*?{\s*?color:\s*?(#00FF00|#0F0)\s*?;\s*?}/gi));
```
Your `h1` element with the text `I am dodger blue!` should be given the `color` dodger blue.
```js
assert($('.dodger-blue-text').css('color') === 'rgb(30, 144, 255)');
```
The `hex code` for the color dodger blue should be used instead of the word `dodgerblue`.
```js
assert(code.match(/\.dodger-blue-text\s*?{\s*?color:\s*?#1E90FF\s*?;\s*?}/gi));
```
Your `h1` element with the text `I am orange!` should be given the `color` orange.
```js
assert($('.orange-text').css('color') === 'rgb(255, 165, 0)');
```
The `hex code` for the color orange should be used instead of the word `orange`.
```js
assert(code.match(/\.orange-text\s*?{\s*?color:\s*?#FFA500\s*?;\s*?}/gi));
```
# --seed--
## --seed-contents--
```html
<style>
@ -77,14 +103,7 @@ tests:
<h1 class="orange-text">I am orange!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -110,5 +129,3 @@ tests:
<h1 class="orange-text">I am orange!</h1>
```
</section>

View File

@ -6,47 +6,85 @@ videoUrl: 'https://scrimba.com/c/cm24JU6'
forumTopicId: 18368
---
## Description
<section id='description'>
# --description--
Just like with hex code, you can mix colors in RGB by using combinations of different values.
</section>
## Instructions
<section id='instructions'>
Replace the hex codes in our <code>style</code> element with their correct RGB values.
<table class='table table-striped'><tr><th>Color</th><th>RGB</th></tr><tr><td>Blue</td><td><code>rgb(0, 0, 255)</code></td></tr><tr><td>Red</td><td><code>rgb(255, 0, 0)</code></td></tr><tr><td>Orchid</td><td><code>rgb(218, 112, 214)</code></td></tr><tr><td>Sienna</td><td><code>rgb(160, 82, 45)</code></td></tr></table>
</section>
# --instructions--
## Tests
<section id='tests'>
Replace the hex codes in our `style` element with their correct RGB values.
```yml
tests:
- text: Your <code>h1</code> element with the text <code>I am red!</code> should have the <code>color</code> red.
testString: assert($('.red-text').css('color') === 'rgb(255, 0, 0)');
- text: You should use <code>rgb</code> for the color red.
testString: assert(code.match(/\.red-text\s*?{\s*?color:\s*?rgb\(\s*?255\s*?,\s*?0\s*?,\s*?0\s*?\)\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am orchid!</code> should have the <code>color</code> orchid.
testString: assert($('.orchid-text').css('color') === 'rgb(218, 112, 214)');
- text: You should use <code>rgb</code> for the color orchid.
testString: assert(code.match(/\.orchid-text\s*?{\s*?color:\s*?rgb\(\s*?218\s*?,\s*?112\s*?,\s*?214\s*?\)\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am blue!</code> should have the <code>color</code> blue.
testString: assert($('.blue-text').css('color') === 'rgb(0, 0, 255)');
- text: You should use <code>rgb</code> for the color blue.
testString: assert(code.match(/\.blue-text\s*?{\s*?color:\s*?rgb\(\s*?0\s*?,\s*?0\s*?,\s*?255\s*?\)\s*?;\s*?}/gi));
- text: Your <code>h1</code> element with the text <code>I am sienna!</code> should have the <code>color</code> sienna.
testString: assert($('.sienna-text').css('color') === 'rgb(160, 82, 45)');
- text: You should use <code>rgb</code> for the color sienna.
testString: assert(code.match(/\.sienna-text\s*?{\s*?color:\s*?rgb\(\s*?160\s*?,\s*?82\s*?,\s*?45\s*?\)\s*?;\s*?}/gi));
<table class='table table-striped'><tbody><tr><th>Color</th><th>RGB</th></tr><tr><td>Blue</td><td><code>rgb(0, 0, 255)</code></td></tr><tr><td>Red</td><td><code>rgb(255, 0, 0)</code></td></tr><tr><td>Orchid</td><td><code>rgb(218, 112, 214)</code></td></tr><tr><td>Sienna</td><td><code>rgb(160, 82, 45)</code></td></tr></tbody></table>
# --hints--
Your `h1` element with the text `I am red!` should have the `color` red.
```js
assert($('.red-text').css('color') === 'rgb(255, 0, 0)');
```
</section>
You should use `rgb` for the color red.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(
code.match(
/\.red-text\s*?{\s*?color:\s*?rgb\(\s*?255\s*?,\s*?0\s*?,\s*?0\s*?\)\s*?;\s*?}/gi
)
);
```
<div id='html-seed'>
Your `h1` element with the text `I am orchid!` should have the `color` orchid.
```js
assert($('.orchid-text').css('color') === 'rgb(218, 112, 214)');
```
You should use `rgb` for the color orchid.
```js
assert(
code.match(
/\.orchid-text\s*?{\s*?color:\s*?rgb\(\s*?218\s*?,\s*?112\s*?,\s*?214\s*?\)\s*?;\s*?}/gi
)
);
```
Your `h1` element with the text `I am blue!` should have the `color` blue.
```js
assert($('.blue-text').css('color') === 'rgb(0, 0, 255)');
```
You should use `rgb` for the color blue.
```js
assert(
code.match(
/\.blue-text\s*?{\s*?color:\s*?rgb\(\s*?0\s*?,\s*?0\s*?,\s*?255\s*?\)\s*?;\s*?}/gi
)
);
```
Your `h1` element with the text `I am sienna!` should have the `color` sienna.
```js
assert($('.sienna-text').css('color') === 'rgb(160, 82, 45)');
```
You should use `rgb` for the color sienna.
```js
assert(
code.match(
/\.sienna-text\s*?{\s*?color:\s*?rgb\(\s*?160\s*?,\s*?82\s*?,\s*?45\s*?\)\s*?;\s*?}/gi
)
);
```
# --seed--
## --seed-contents--
```html
<style>
@ -73,14 +111,7 @@ tests:
<h1 class="blue-text">I am blue!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -106,5 +137,3 @@ tests:
<h1 class="blue-text">I am blue!</h1>
```
</section>

View File

@ -6,15 +6,22 @@ videoUrl: 'https://scrimba.com/c/cRkp2fr'
forumTopicId: 18369
---
## Description
<section id='description'>
Another way you can represent colors in CSS is by using <code>RGB</code> values.
# --description--
Another way you can represent colors in CSS is by using `RGB` values.
The RGB value for black looks like this:
<code>rgb(0, 0, 0)</code>
`rgb(0, 0, 0)`
The RGB value for white looks like this:
<code>rgb(255, 255, 255)</code>
Instead of using six hexadecimal digits like you do with hex code, with <code>RGB</code> you specify the brightness of each color with a number between 0 and 255.
If you do the math, the two digits for one color equal 16 times 16, which gives us 256 total values. So <code>RGB</code>, which starts counting from zero, has the exact same number of possible values as hex code.
`rgb(255, 255, 255)`
Instead of using six hexadecimal digits like you do with hex code, with `RGB` you specify the brightness of each color with a number between 0 and 255.
If you do the math, the two digits for one color equal 16 times 16, which gives us 256 total values. So `RGB`, which starts counting from zero, has the exact same number of possible values as hex code.
Here's an example of how you'd change the body background to orange using its RGB code.
```css
@ -23,31 +30,27 @@ body {
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Let's replace the hex code in our <code>body</code> element's background color with the RGB value for black: <code>rgb(0, 0, 0)</code>
</section>
Let's replace the hex code in our `body` element's background color with the RGB value for black: `rgb(0, 0, 0)`
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your <code>body</code> element should have a black background.
testString: assert($("body").css("background-color") === "rgb(0, 0, 0)");
- text: You should use <code>rgb</code> to give your <code>body</code> element a color of black.
testString: assert(code.match(/rgb\s*\(\s*0\s*,\s*0\s*,\s*0\s*\)/ig));
Your `body` element should have a black background.
```js
assert($('body').css('background-color') === 'rgb(0, 0, 0)');
```
</section>
You should use `rgb` to give your `body` element a color of black.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/rgb\s*\(\s*0\s*,\s*0\s*,\s*0\s*\)/gi));
```
<div id='html-seed'>
# --seed--
## --seed-contents--
```html
<style>
@ -57,14 +60,7 @@ tests:
</style>
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```html
<style>
@ -73,5 +69,3 @@ tests:
}
</style>
```
</section>