ARCHOSC-HTML-CSS-JavaScript

HTML, CSS and JavaScript Basics

Section 1

To this point, your repository probably looks something similar to the image below:

Image

The first thing you need to do is add a CSS and Javascript folder into your project.

In Visual Studio Code, click file -> new text file.

Image

In the created file, click file -> save as and name your file styles.css, saving it in the same folder as your index.html file.

Image

When saved, your local repository folder should look like this:

Image

You now need to reference your CSS and JavaScript in your HTML itself, to do this you need to add the lines:

<link rel="stylesheet" href="styles.css">

to the header of your HTML document

and

<script src="script.js"></script>

to the bottom of the body section of your HTML document.

This means that your HTML will now be able to talk to both your CSS and JavaScript documents.

Now you have one HTML file working with your CSS and JavaScript we now need to add HTML pages for each of the labs you have completed so far.

Create a new text file in Visual Studio Code, as you did previously. And this time, copy the following into the document:

Image

When you are done, save your HTML document, I am going to call it “GitHub1.html” but you can call it whatever will help you remember!

Image

Section Two

Image

Once you have done this, add the following code to your index.html

<h1>Welcome to my Portfolio!</h1>

Then add the following Underneath

<h2>By [Your Name Here]</h2>

And then, finally,

<p>This portfolio contains screenshots and definitions for all of the tasks I have completed in my lab. </p>

Save your HTML file and open your website, it should look like this:

Image

Now, to add some design to your porfolio.

Open your styles.css file, and make it look like the image below.

Image

Save everything, and re-open your website. You should see that your heading is now Orange.

Now we are able to change items by their tag, the next step is to change items based on their class. This will allow us to change individual elements, without changing an entire page.

To do this we must first assign some of our HTML a class to begin with.

Go back to your index.html folder and change.

<h2>By [Your Name Here]</h2>

to

<h2 class="name">By [Your Name Here]</h2>

and

<p>This portfolio contains screenshots and definitions for all of the tasks I have completed in my lab. </p>

to

<p class="description">This portfolio contains screenshots and definitions for all of the tasks I have completed in my lab. </p>

When done your index.html file should look similar to this (obviously with your name - not mine!)

Then return to your CSS file, and add the following:

Image

Save everything and refresh your web page.

Your text should now be orange, green and pink!

Now, we also want to be able to access our classes from within our JavaScript.

Open your JavaScript document and add this line

const myName = document.querySelector(".name");

You should then add another variable below, that gets access to your “description” class.

Underneath this add the following lines.

console.log(myName);
console.log(THE NAME OF YOUR DESCRIPTION VARIABLE);

This will allow us to check and see if your classes are being picked up correctly.

Save everything, and open your website in the browser. Nothing should have changed.

Press F12 on your keyboard to open the developer console. If you are using Edge you may get a prompt asking if you want to do so - you are fine to click “Open Dev Tools”

When open it should look like this:

Image

Select the button below, to open the console

Image

Once open, the console should show your two classes, if you can hover over them and they light up correctly on the page you know that your JavaScript is picking them up properly.

Image

Section 3

Now you can access, and edit your HTML with CSS and JavaScript, you need a way to access the other pages you created (with all of your work in!)

We’re going to start with the easiest way of doing this, a list of links to the other pages.

Add the following code to your index.html file.

<h4>Pages</h4>
<ol>
    <li>><a href="GitHub1.html">GitHub Lab 1</li>
    <li>><a href="WriteTheNameYouGaveTheLabeHere.html">Named Lab 2</li>
    <li>><a href="WriteTheNameYouGaveTheLabeHere.html">Named Lab 3</li>
</ol>

Save your HTML file with the pages added, and open your website in the browser, it should look like the image below (my GitHub Lab 1 is only purple becuase I checked it’s working):

Image

With this, you have the foundations of Website Navigation, and it works! But to complete your Portfolio you should aim to implement a proper Nav Bar.

Section 4

The final aspect of your portfolio you are going to work on today is implementing a Dark Mode on to your website.