This website is available at: https://alfieho.github.io/project2
Before working on this project:
-
In your web browser, make a web server for your project by forking the project and turning on GitHub “Pages”:
-
Clone (make an exact copy of) this project by clicking the “Fork” button. And then the “Create fork” button.
-
After the fork is finished, click the “settings” tab.
-
On the left side, click the “Pages” link.
-
Under the “Branch” heading, change “None” to “main”.
-
Click the “Save” button.
-
Click the “Code” tab on the top left side.
-
-
Clone the project to your laptop.
-
In VS Code, choose “File” → “New Window”.
-
In the “Welcome” tab, choose “Clone Git Repository…”. (If you don’t have a “Welcome” tab, from the drop-down menus, choose “Help” → “Welcome”. Then make sure the “Show welcome page on startup” option is checked.)
-
At the top of the VS Code window, click “Clone from GitHub” and choose the option that is “your_username/project2”.
-
Find your Documents → School → Code folder and choose “Select as Repository Destination”.
-
When asked “Would you like to open the repository?”, choose “Open”
-
You should see a prompt that says “This folder contains a workspace file 'project2.code-workspace'. Do you want to open it?” Click the “Open Workspace” button.
-
-
Change the URL at the top of this file.
-
Open the
README.mdfile. -
Replace
MY_USER_NAMEwith your GitHub username; for example:johnalbin. -
Save this file!
-
When helping a classmate:
-
Don’t do the fix for them. (Don’t act like an AI that washes their clothes.)
-
Let them do the fix. Let the person being helped do all the typing and clicking.
-
Tell them what to do.
-
Also, tell them why it was broken or why your fix works.
Preview this file (instead of looking at its code):
-
If the “README.md” tab above is in italics, open the
…menu to the tab’s right and un-check the “Enable Preview Editors” option. -
If you don’t have a “Welcome” tab, from the drop-down menus, choose “Help” → “Welcome”. Then make sure the “Show welcome page on startup” option is checked.
-
Right-click (or two-finger click) on the “README.md” tab above and choose “Open Preview”.
-
Right-click on the “Preview README.md” tab above and choose “Split & Move” → “Move Right”.
-
Close the “README.md” tab on the left. (Don’t close the “Preview” tab.)
🙋🏻 Don’t forget: you can ask questions at anytime! That’s how you learn. 🧠🧐
-
Create a new
index.htmlfile. -
Add boilerplate HTML markup to the file.
-
You should add the following HTML elements:
- <!doctype html>
- html
- head
- title
- body
- header
- div
- div
- img
- b
- menu
- a
- button
- div
- div
- main
- h1
- footer
- div
- p
- div
- script
- header
Be sure to use closing tags when needed. Be sure to nest elements correctly. (“nest” means to put one thing inside another.)
We are using 5 new HTML elements:
menuA list of links that are a menu of choices for page navigation. (navigate means to move around inside something with a plan or purpose. You can navigate the ocean, navigate a website, or navigate a city.)mainEverything inside this element is the page’s main content (the most important information).headerJust like the page has afooter, it can also have a header. We usually put the website name and the website navigation inside theheader.divA content division. A generic box with no default styles. (Compare with thepelement which has margins by default.) Inside thebodyelement, adivcan contain any other HTML element.bMakes text bold.
-
Inside the
titleandh1elements, add the text:Project 2: A Clean Slate -
Inside the
belement, add your name. -
For the
imgelement, use theavatar.pngfile that is in your project’simagesfolder. -
Inside the
alink element in themenu, add the name of your previous project (week1 or week2). And add the URL to the website for that project as an attribute on theaelement.Do you remember what attribute to use on the link element? If you don’t remember, look at your last project or ask for help.
What’s the URL for your first project’s website? _Hint: it’s the same as the URL at the top of this file, but with
project2replaced with the name of your first project. -
Inside the
buttonelement in themenu, add the text:Light mode. Give that button anidattribute ofcolor-mode-button. -
Inside the footer’s
pelement, add today’s date. -
We will leave the
scriptelement empty for now.
-
-
Add some content to the page.
-
Just underneath the
h1, copy and paste the following HTML:<p> How do we center the content in our browser window? How wide should our content be? How wide should our content be if we look at our webpage on a phone’s browser? </p> <h2><i>A poem</i></h2> <p> A website is a work of art<br /> A poem for the digital age<br /> Built with skill and heart<br /> To inspire while filling the page </p>
What new HTML elements did we use above? Test it in your web browser.
- Do you think you know what the “br” stands for? Hint: “line br…”
- What do you think the
ielement stands for?
-
Have a teacher review your work so far.
-
Save your file. Then use Git to add your changes and make a commit. You can choose your own commit message.
-
-
Add page styles.
-
Create a
stylesfolder and then create apage.cssfile insidestyles. -
Add the following CSS:
* { box-sizing: border-box; } body { padding: 20px; /* TODO Add dark mode styles here. */ } .light-mode { /* TODO Add light mode styles here. */ } .center { width: 940px; padding: 20px; border: 1px dotted white; /* TODO Add margins to center. */ } .poem { text-align: center; } footer { /* TODO Add styles */ } .light-mode footer { /* TODO Add footer light mode styles here. */ }
You can copy and paste the CSS above.
-
Add a dark background and light text to our page.css using the element selector:
body -
Add a
<link>on ourindex.htmlfile that will load ourpage.cssstyles.Where does the
linkelement go in our HTML file? -
Find the
pafter ourA poemheading. Add aclassattribute set topoem.Notice how the styling of the poem changes. What CSS property made that change?
-
Add a background color to the
footerelement. -
Add light mode styles to the
page.cssfile. When we write the JavaScript later, thelight-modeclass will be added to thebody.Notice we have this rule:
.light-mode {}This allows us to write light mode styles in the same file as our default dark mode styles.We also have a
.light-mode footer {}rule. This allows us to change the light mode styling of<footer>right next its dark mode styling.
-
-
Learn about CSS’s box model:
-
Here’s a diagram showing
margin,border, andpaddingCSS properties.If you only want to change the margin, border or padding of one side of the box, you can use one of these properties:
margin-top,margin-bottom,margin-left,margin-rightborder-top,border-bottom,border-left,border-rightpadding-top,padding-bottom,padding-left,padding-right
-
Next is a diagram showing what happens when you set
widthto a specific length, like this:.example { border: 15px solid grey; padding: 20px; width: 200px; }
The above diagrams show CSS’s “box model”. The element’s box is defined with a
widthorheight. Theborderis the edge of the box and itspaddingis the spacing between the border and the content. Themarginis the spacing on the outside of the box.In the example above, the width of the box is
200px. Since the border is15pxthick and the padding is20pxthick, the space left for the content of the box is130px. How was that calculated? Don’t forget that there are borders and padding on the left and the right. -
If the
widthisauto(the default), the box width will take up all remaining space inside the window. If thewidthis set to a specific length (like200px), you can set themargin-leftandmargin-righttoautoand the two margins will split the remaining space equally. This will center the box in the window. -
Open our
index.html. Add acenterclass attribute todivelement inside thefooterelement. -
Open our
page.cssfile. Edit the.centerrule so that the box is centered. Hint: what properties do we need to add to that rule? Re-read step C above.
-
-
Add color mode JavaScript.
-
Create a
scriptsfolder and then create acolor-mode.jsfile insidescripts. -
In the
index.htmlfile, add aclassattribute to thebodyelement using the value ofdark-mode.Why did we use a
classinstead of anidlike last time? Is “Dark mode” an unique name (id) or a category (class)? What do you think? -
In the
index.htmlfile, edit thescriptelement by adding asrcattribute that points at our newcolor-mode.js -
Write the JavaScript to toggle color modes. We will be writing all this JavaScript inside the
color-mode.jsfile.-
Find the color button using
document.getElementById(); the first parameter will be theidattribute on the<button>. Save the button element found to a variable namedbutton. -
Define a function named
toggleColorMode-
It will have one parameter; name the parameter
event. -
Write
if/elseblocks that test if thedocument.body.classListobject containsdark-mode.The
classListobject has acontains()function that can test if a class is in the class list. -
In the
ifblock:-
Set the button’s text to “Dark mode” using:
button.textContent = "Dark mode"; -
Replace the
bodyelement’sdark-modeclass withlight-mode.The
classListobject has areplace("old", "new")function that can replace an old class with a new class. That function has two parameters; the first is the old class to be removed and the second is the new class to be added.
-
-
In the
elseblock, do the opposite as theifblock. -
After the
if/elseblocks, add this:console.log("event =", event);
-
-
Tell the
buttonto use thetoggleColorModefunction when it is clicked.-
We won’t be using HTML to do this. Last time we used the
onClickattribute on<button>. -
We will be using JavaScript to add a function that is run when the button’s click event happens.
In our
color-mode.jsfile, we will use theaddEventListener("click", nameOfFunction)function that is on everyHTMLElementobject.Use this JavaScript:
// Run our function when the button is clicked. button.addEventListener("click", toggleColorMode);
-
-
-
If you have extra time, you should try out these other CSS properties.
-
Add some fonts!
-
Look at the Google Fonts website.
-
Look at the filters on the left side, especially the “Feeling”, “Appearance”, and “Seasonal” filters.
-
When you find a font, click on it.
-
Then click on the “Get font” button.
-
Then click on the “Get embed code” button.
-
-
Copy the code under “Embed code in the
<head>of your html” and put it in yourindex.htmlfile. -
Under the “CSS class”, copy the
font-familyline and put it in yourpage.css’sh1rule. -
Find another font and add to your CSS as above. This time add the
font-familyline to yourbodyrule.
-
-
Learn about
border-radius!Add a
background-colorandcolorto your button. Then addborder-radius: 5px;to your button.What happens when you use
border-radius: 50%? Fifty percent of what? (It's fifty percent of the width or height.)What happens when you use
border-radius: 0 20px 20px 0;? -
Learn about
box-shadow!You can add a
box-shadowto any HTML element that creates a box. (Some elements, like<b>and<i>, are used inline with text and do not create a box.)-
Try adding this to your button styles:
box-shadow: 10px 5px 5px 0 red;
-
Try changing the values to see what happens. What happens when you use
0for some of the values? -
Try changing the
border-radiusof the button while it has a shadow. How does the shadow change?
-
-
Make your page responsive.
Responsive website design is a technique to make a website look good on desktop computers and mobile devices (like phones and tablets). It does this by using slightly different CSS styles for different window widths.
The full techniques (skills) for doing this are more advanced than we will learn, but here’s some simple techniques.
-
Open your page in your browser. Make the browser window narrower.
What happens when your window is narrower than your
.centerrule’swidth? -
To prevent your content from going off the right edge of the browser window (and showing a horizontal scrollbar), use the
max-widthproperty in your.centerrule instead of thewidthproperty.
-
-
Learn about
backgroundgradients!-
Add this to our footer styles:
background-image: linear-gradient(to bottom, darkslateblue, darkslategrey);
-
You change the direction of the gradient with
to top,to left, orto right. -
There are many, many other options. If you want to learn more, read the CSS Tricks’ article about linear-gradient.
-


