For this lab, you will design a consistent layout of all the webpages in a website using HTML and CSS. Then, you will develop content pages using the layout you developed.
1. Designing a Layout Page
2. Developing Content Pages from the Layout Page
3. Developing an Additional Page for the Website from the Layout Page
4. Verifying your HTML and CSS Files
Create a working folder for the lab assignment. Launch Visual Studio Code and click File -> Open Folder. Navigate to the folder you created and open the folder.
Download "Lab 7 Data.zip" and extract all files to the "images" folder under your project folder. Make sure you have the following:
Part 1-1 - Create a Standard Layout Page
When you design a webpage layout, it is useful to divide your content into multiple sections. Suppose you want to have a common user interface (i.e. layout) with a common header and a set of navigation links on the top, a "main content" in the middle, and a footer at the bottom as shown in the following figure. To implement this layout, you need to wrap up each section in < header >, < nav >, < div >, < footer > elements in your HTML page.
Figure: see image.
1. Right click on the folder (lab7) on Explorer in Visual Studio Code, click "New File", and create frame.html.
2. Setup the initial structure of your HTML page with the following components.
3. In the body section, add < header >, < nav >, < div >, and < footer > elements to define sections of header, navigation menu, main content, and footer in your webpage.
4. Set an ID for the div for the main content. Recall the ID property of < div > elements are used to specify and target an element for CSS styles through a CSS ID selector!
< body >
< !-- Define the header element -- >
< !-- Define the nav element -- >
< !-- Define the div element for the main content -- >
< !-- Make sure you give the div element a unique ID to access with CSS! -- >
< !-- Define the footer element -- >
< /body >
5. Write a copyright in the footer section. is an HTML character entity used to represent a copyright character . Add your own name. For more info about HTML character entities: https://www.w3schools.com/html/html_entities.asp.
6. Next, make a set of navigation links in the nav section in frame.html.
7. Save and run frame.html in a web browser. It should look like the figure below.
Figure: see image.
Part 1-2 - Setup the Style for the Layout Page Header with CSS
1. To apply different styles to your webpage, create a CSS file. Click "New File" and type a filename of your choice (e.g. layout.css).
2. Specify the external style sheet file (layout.css) in the head section of frame.html using the < link > tag.
3. Apply the following CSS styles to the < header > element in layout.css.
Target the header element using an element selector and add the following styles:
html {
/* Set the height to 100% */
}
body {
/* Set the height to 100% */
}
header {
/* Complete your code here */
}
4. Save layout.css and preview frame.html in a browser. You may see the margin around the < body > element which is the default margin set by the browser.
Figure: see image.
5. If you don't want to have any space around the < body > element, in your CSS file, set the margin property of the < body > element to 0px. Add this to your CSS file.
6. Save layout.css and preview frame.html again in a browser.
Figure: see image.
Part 1-3 - Setup the Style for the Layout Page Nav Bar with CSS
7. Now you will apply styles to the navigation links to improve their appearance. Your stylesheet (layout.css) should include the following.
nav {
/* Complete your code here */
}
nav a {
/* Complete your code here */
}
8. Save layout.css and preview frame.html in a browser. You may notice the width and height of the < a > elements you specified in the CSS file are not working. They depend on the width and height of the text of the link. This is how browsers render links normally.
Figure: see image.
To remove normal positioning of the link elements and make each link float to the left and keep its width, set the float property of the nav link elements to left.
9. Save layout.css and preview frame.html in a browser.
Figure: see image.
Part 1-4 - Finalize the Style of the Nav Bar Link Elements
10. The navigation menu in the above figure doesn't look good, so apply the following styles to the navigation menu nav link elements to improve its appearance.
11. Save layout.css and preview frame.html. It should look something like below.
Figure: see image.
13. Add different styles for when a user hovers over a menu link by using a descendant pseudo-class selector "hover" by adding the following to your CSS file.
/* Define a pseudo-class selector for when the user hovers over a link element in the nav */ {
/* Complete your code here */
}
14. Save layout.css and preview frame.html. It should look something like below.
Figure: see image.
Part 1-5 - Add Styles to the Layout Page for the Footer with CSS
1. Now you will position and fix the footer to the bottom of the webpage.
2. Add at least three (3) styles to paragraph < p > elements in the section of the footer div using a descendant selector (e.g. font, color, text-align, etc.).
/* Define a descendant selector to select paragraph elements in the footer */ {
/* Complete your code here */
}
Part 1-6 - Add Styles to the Layout Page for the Heading with CSS
1. In frame.html, add a heading (h1) element that contains the text "Coffee Factories" in the header section of your HTML page.
2. Target the h1 element in the header. Add at least four (4) styles to the heading (e.g. font, color, padding, text-shadow, margin-block-start, margin-block-end, etc.).
3. Save layout.css and preview frame.html. It should look like the following image.
Figure: see image.
The layout designed for frame.html will be used as the layout of the following pages:
All pages will be stylized using the following external CSS file:
Part 2-1 - Creating an Index Page
1. Open frame.html and save it as index.html in your working directory. The page index.html will be the home page for your website.
2. Change the title of the page (e.g., "About Us").
3. Click New File and create a CSS file. Type a filename of your choice (e.g. content.css)
4. Make a link to the external stylesheet (content.css) in the head section of index.html using the < link > tag.
5. Edit content.css to set a background image that covers the main content div.
6. Save content.css and preview index.html. It should look like the following image.
Figure: see image.
7. Open index.html. Add the following contents to the main content div.
8. Apply the following CSS styles to the < article > element in content.css.
9. Save content.css and preview index.html. It should look like the following image.
Figure: see image.
Part 2-2 - More on Background Image
Add enough content to the "main content" div so the content of the div element overflows the height of the browser window. When you scroll down your page, the background image will not cover the space exceeded the height of the browser window as you see below: see image.
How can you make the background image cover all the content? The solution is to set the background image for the < body > element instead of the main content div element.
Open content.css, comment out (do not delete) the styles applied to the main content div, and edit the CSS file to apply following styles. Save content.css when you are done.
Figure: see image.
Part 2-3 - Add Some JavaScript for User Input to the Index Page
1. Add a < script > tag for some JavaScript code to the head section of index.html.
2. Add a prompt for the user to enter their name. Save the output to a variable.
3. Add a prompt for the user to enter their favorite bean. Save the output to a variable.
4. Add an alert to welcome the user based on the info they entered. See Example Output below.
Figure: see image.
On your own, create one additional page (as defined above) that you have not yet created for your website (e.g., coffeebeans.html; brewguides.html; locations.html).
When done, you should be able to switch between the pages of your site using the navigation links!
Check for errors in your HTML and CSS files:
If the validators find any significant (i.e., not minor) errors in your files, you should fix them. You should not submit the validation results, but use these tools to correct your code.