Skip to content

Commit

Permalink
feat(challenges): add browser fallback challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
joshalling authored and scissorsneedfoodtoo committed Aug 30, 2018
1 parent 72c2407 commit b090e8b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions challenges/01-responsive-web-design/basic-css.json
Original file line number Diff line number Diff line change
Expand Up @@ -5546,6 +5546,51 @@
}
}
},
{
"id": "5b7d72c338cd7e35b63f3e14",
"title": "Improve Compatibility with Browser Fallbacks",
"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.",
"<hr>",
"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."
],
"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.match(/.red-box\\s*{[^}]*background:\\s*(red|#ff0000|#f00|rgb\\(\\s*255\\s*,\\s*0\\s*,\\s*0\\s*\\)|rgb\\(\\s*100%\\s*,\\s*0%\\s*,\\s*0%\\s*\\)|hsl\\(\\s*0\\s*,\\s*100%\\s*,\\s*50%\\s*\\))\\s*;\\s*background:\\s*var\\(\\s*--red-color\\s*\\);/gi), '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.');"
}
],
"solutions": [
"var code=\".red-box {background: red; background: var(--red-color);}\""
],
"challengeType": 0,
"translations": {},
"files": {
"indexhtml": {
"key": "indexhtml",
"ext": "html",
"name": "index",
"contents": [
"<style>",
" :root {",
" --red-color: red;",
" }",
" .red-box {",
" ",
" background: var(--red-color);",
" height: 200px;",
" width:200px;",
" }",
"</style>",
"<div class=\"red-box\"></div>"
],
"head": [],
"tail": []
}
}
},
{
"id": "5a9d7295424fe3d0e10cad14",
"title": "Cascading CSS variables",
Expand Down

0 comments on commit b090e8b

Please sign in to comment.