Web Development: Additional Topics Challenges
With any remaining time, make updates to the webpage by following these instructions!
HTML Challenge: Embed a YouTube video
- Open a new tab and go to YouTube
- Search for an appropriate video (e.g., color red)
- Under the video, click the "SHARE" button
- Click "Embed"
- Click "COPY"
- In the CodePen, paste the code at the bottom of the HTML section
- Use
Ctrl
+v
or right-click and select "Paste"
- Use
- Watch the video on your website!
The code should look something like this:
<iframe width="560" height="315" src="https://www.youtube.com/embed/7zkX6kfnWbk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
CSS Challenge: Header Text Shadow
- In the CSS section, under the
}
from the "body" ruleset, make some new lines - Create a new ruleset for "h1" by adding
h1
and{
and}
- This will mean that all styles apply to each
h1
HTML element - Note that when adding the opening bracket (
{
), CodePen adds the closing bracket (}
) automatically - With the cursor between the two brackets, press the "Enter" key to properly format the ruleset
- This will mean that all styles apply to each
- Within the brackets, add a new declaration:
text-shadow: red -1px 1px
- Update the numbers and the color to see how it changes the effect!
- For more information, check out this article: https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow
The code should look something like this:
h1 {
text-shadow: red -1px 1px;
}
CSS Challenge: Create a Gradient Background or a Background Image
- In the CSS section, within the
body
ruleset, remove thebackground
value - Replace the value with a
linear-gradient
containing two colors (see code below) - Change the values to see how it changes the gradient!
body {
/* ... */
background: linear-gradient(#9198e5, #e66465);
/* ... */
}
Note: Go cssgradient.io to customize the gradient!
It is also possible to give the page a background image:
- Find an image online
- Copy the image address
- Update the
background
declaration in the CSS with aurl
containing the image address in quotes
body {
/* ... */
background: url("https://cdn141.picsart.com/301292961077211.png?r1024x1024");
/* ... */
}
CSS Challenge: Change Text Color on Hover
- In the CSS section, create a new ruleset for
li
- The styles in this ruleset will only affect
li
elements
- The styles in this ruleset will only affect
- Add the
color
property with a value oforange
- Notice that the text color changed
- Update the selector so that instead of
li
, it isli:hover
- This means the styles will only apply when the user hovers over the
li
elements
- This means the styles will only apply when the user hovers over the
- Update the values to change the effect!
li:hover {
color: orange;
}
JavaScript Challenge: Add an Alert Button
Add a button to the webpage that will display a message when someone clicks it.
HTML
- In the HTML section, add a new element:
button
- Add the opening tag:
<button>
- Add some text for the button
- Add the closing tag:
</button>
- Add the opening tag:
- Make sure the button appears on the page with the proper text
- Inside the opening tag for the button, after the word
button
before the>
, add a space - After the space, add an
onclick
attribute set equal torun()
- Add
onclick
- Add an equals sign
- Add quotation marks
- Between the quotation marks, add
run()
- This
onclick
will trigger JavaScript code to run when the button is clicked!
- Add
<button onclick="run()">Click Me!</button>
JavaScript
The button needs a function to call, which will contain some code commands. Basically, defining a function will tell the button what to do when it is clicked.
- Expand the JS section
- Type the word
function
- Make a space, and type in
run()
- This must match the value inside of the
onclick
in the HTML
- This must match the value inside of the
- Type in a left curly bracket
- The right curly bracket should be added automatically, like in CSS
- Press enter to go between the curly brackets on a new line
- Type in
alert
- This command will display a message
- After
alert
, type in a left parenthesis:(
- This should automatically add a right parenthesis, and the cursor should be in between the two parentheses
- Between the parentheses, type in a double quote:
"
- Another double quote should be added automatically
- Between the quotes, type in a message to show
- Add a semi-colon at the end of the line
- Try to click the button after the page re-loads, and make sure a message appears!
function run() {
alert("Hello!");
}