Contents  >

Smoothies Project:
Menus

Introduction

In this task you will use template content to add desktop and mobile menus to the ‘Smoothies’ project you created earlier and to which you then added an email sign-up form and a footer

You can display a finished version of the project web page by clicking the image below.

Web Design Project: Smoothies 2n2l.com Brendan Munnelly

Learning Goals

At the end of this Tutorial you will be able to:

Contents

Introduction

Creating the hero block

Downloading the website logo image

Working with your two HTML files

Copying-and-pasting the menus HTML and JavaScript

Working with the template CSS file

Copying and renaming the template CSS file

Removing browser resets from the new menus CSS file

Updating the font-family for the menus

Linking your web page to the new menus CSS file

Updating the menu logo and hyperlink

Updating the menu option hyperlinks

Creating the hyperlink destinations

Offsetting the hyperlink destinations

Updating the mobile menu content and hyperlinks

Updating the menu colours

Adding the menu style-swapping effect

Darkening the upper part of the hero image overlay

Changing the colour of the hamburger icon

Uploading your project to GitHub

Creating the hero block

Your first step is the create a hero block for the ‘Smoothies’ project. Follow these steps.

  1. Right-click the image below and, from the context menu displayed, choose Save Image As. smoothies-logo.png Download the image file to your websites/portfolio/smoothies/assets/img sub-folder that holds the other image files for this project. file-explorer-full
  2. In Visual Studio Code, from your websites/portfolio/smoothies folder, open the web page named index.html. smoothies-logo.png
  3. Copy-and-paste the following to the top of the web page, just after the start of the opening <body> tag.
      <!-- Begin hero block -->
      <header class="container-hero">
        <h1>Smooth Smoothies</h1>
        <h2>Where flavour meets goodness</h2>
      </header>
    <!-- End hero block -->
    
  4. Next, open the style.css file from your websites/portfolio/smoothies/assets/css folder. smoothies-logo.png
  5. Copy-and-paste the following at the top of the stylesheet, just after the == WEB BROWSER RESETS == block.
      /* === STYLES FOR HERO CONTAINER AT TOP OF WEB PAGE === */
    
      /* ==== Hero block general properties ==== */
      .container-hero {
         display: flex;
         flex-direction: column;
         justify-content: center;
         background-image: linear-gradient(rgba(0,0,0,0.2),rgba(0,0,0,0.2)),url('../img/smoothie-hero-image.jpg');  
         background-position: center center;
         background-size: cover;
         background-repeat: no-repeat;
      }
    
      /* === Heading and sub-heading === */
      .container-hero h1, .container-hero h2 { 
          font-family: 'Neucha', sans-serif;
          text-align: center;
          color: #fff;
          text-shadow: 2px 2px #222;
      }
    
      .container-hero h1 {
          font-size: calc(58px + (132 - 58) * ((100vw - 320px)/(1600 - 320)));
          line-height: 1.1
      }
    
      .container-hero h2 {
          font-size: calc(26px + (64 - 26) * ((100vw - 320px)/(1600 - 320)));
      }
    
      /* Desktops - container height and h1 bottom margin */
      @media (min-width: 768px) { 
          .container-hero { height: 520px }
          .container-hero h1 { margin-bottom: 1% }
      }
    
      /* Mobiles - container height, text width and h1 bottom margin */
      @media (max-width: 767px) { 
          .container-hero { height: 360px }
          .container-hero h1 { margin-bottom: 5% }
      }
  6. When finished, save the index.html and style.css files.

In your web browser, the ‘Smoothies’ web page should look as shown below.

fa-icons-copy

Working with your two HTML files

You will begin by working with two HTML files:

  1. In VS Code, from your websites/templates folder, open the following HTML file:   menus-template.html fa-icons-copy
  2. From your websites/portfolio/smoothies folder, open the index.html web page.

If you have any other files open in Visual Studio Code, you may wish to close them.

fa-icons-copy

This will help you to focus only on the two HTML files you will be working with.

Copying-and-pasting the menus HTML and JavaScript

Your next step is to copy content from the menus template file into your index.html web page.

  1. In the menus-template.html file, select and copy the menus-related HTML blocks. fa-icons-copy
  2. In your index.html web page, click just after the start of the opening <body> tag, and press the ENTER key a few times to open up some new lines of blank space.
  3. Paste the copied HTML for the menus.
  4. Switch back to the menus-template.html file, and select and copy the JavaScript code for the menus. fa-icons-copy
  5. In your index.html web page, scroll down to near the end of the web page, to just before the closing </body> tag.
  6. Press the ENTER key a few times to open up some new lines of blank space.
  7. Paste the copied JavaScript code for the menus.
  8. When finished, save your index.html web page.

You can close the menus-template.html file. You are now finished working with this template.

Updating the mobile menu content and hyperlinks

In the lower part of the mobile menu, under the <hr> horizontal rule line, you can include some text about yourself, an image and some hyperlinks.

  1. If you wish to include a profile picture, the link to the placeholder image is as follows.
    <img src="assets/img/profile-pic.jpg" alt="Mary Smith, Web Designer"> 
    
  2. If you wish to include an email address or social media hyperlinks, replace the template-provided details with your own. Delete any details in the template you do not want to include.
  3. If you want to link your website's Home page, the link should be as follows.
    <a href="../../index.html">Home</a>
    
  4. If you want to link your website's Portfolio page, the link should be as follows.
    <a href="../index.html">Portfolio</a>
    
  5. And if you want to link your website's Contact Form page, the link should be as follows.
    <a href="../../contact/index.html">Contact</a>
    
  6. Save your index.html web page.

Updating the menu colours

In the menus-template.html file you copied-and-pasted into your index.html web page, the CSS class of menu-light is assigned to the desktop and mobile menus. As a result:

Let’s replace this default colour of red with the deep pink colour of #d1274b used elsewhere in the web page.

  1. In VS Code, open the menus.css stylesheet.
  2. From the VS Code menubar, click the Edit option and then choose the Replace command.
  3. A new search-and-replace dialog box appears at the top-right of the Visual Studio Code screen. fa-icons-copy
  4. In the first field, enter red.
  5. In the second, enter #d1274b.
  6. Click the left icon for Replace. Do not click the right icon for Replace All.
  7. One by one, replace every occurrence of the colour red with #d1274b.   (If you choose the Replace All option, VS Code will replace the letters 'red' inside words such as 'centered' that may be written in comments.)
  8. Save the menus.css file.

In your web browser, the web page should look as shown below.

fa-icons-copy

Adding the menu style-swapping effect

Your final step is to use some JavaScript code in the menus-template.html file you copied-and-pasted into your index.html web page to create the following effect:

To achieve this effect, follow these steps.

  1. In the index.html file, for the menu-related blocks below, replace the class of menu-light with the menu-transparent class. fa-icons-copy
  2. Scroll down to near the bottom of the web page, and remove the // characters from the beginning of the JavaScript code as shown below. fa-icons-copy
  3. Save the index.html web page.

In your web browser, the web page should look as shown below as you scroll down and back up the screen.

fa-icons-copy

When the user scrolls down the web page:

When the user scrolls back up the web page:

Darkening the upper part of the hero image overlay

In your style.css file, you can see that the hero image has a black-coloured overlay.

fa-icons-copy

Its purpose is to make the heading and sub-heading of the hero block easier to read against the image background. The overlay has a low value of 0.2, so that the image does not appear too dull.

Your task is to darken the overlay — but only for the upper part of the hero image that is behind the text of the menu options. The aim is to make the menu option text easier to read.

  1. In the style.css file, for the container-hero class, increase the upper value of the overlay opacity gradient of the background-image property to 0.6. fa-icons-copy
  2. Save the style.css file. You can now close this stylesheet.

Changing the colour of the hamburger icon

The hamburger icon, which is displayed only on mobile screens, is shown in the same deep pink colour as the menu options text whenever the menu has a transparent background.

To make the hamburger icon more visible against the background image, let’s change its colour from deep pink to white.

  1. In VS Code, open the menus.css stylesheet.
  2. Change the icon colour, which is created by the background-color property, to white (#fff). fa-icons-copy
  3. Save the menus.css file. You can now close this stylesheet.

That’s it. You have now completed your ‘Smoothies’ project.

You can display a finished version of the project web page by clicking the image below.

Web Design Project: Smoothies 2n2l.com Brendan Munnelly

Uploading your project to GitHub

All the files you have updated for this project are in the smoothies sub-folder of your websites/portfolio folder.

So the easiest option is simply to upload the entire smoothies sub-folder to your account on GitHub.

  1. If you are not already signed in to your GitHub account, sign in now.
  2. On the left of your GitHub home page, click the name of the repository that holds your web pages.
  3. On the next GitHub screen displayed, click the portfolio folder. GitHub Upload
  4. GitHub should now display your portfolio folder. github-upload-portfolio
  5. With the portfolio folder displayed on your GitHub screen, click the Add file button and, from the dropdown list displayed, choose the option Upload files. Project Animation Google Fonts
  6. In File/Windows Explorer on your computer, display your portfolio folder and then drag-and-drop the smoothies folder to the GitHub tab in your web browser. github-upload-drag-drop
  7. After uploading the smoothies folder, scroll down to the bottom of the GitHub screen, enter a short message in the Commit changes box, click the Commit changes button, and wait for the upload to complete. github-upload-progress

Your updated ‘Smoothies’ project web page project is now published on GitHub at a web address similar to the following, where username is the username you have chosen for your GitHub account:

https://username.github.io/portfolio/smoothies/index.html

or, simply:

https://username.github.io/portfolio/smoothies

It may take a few minutes for your uploaded files to appear on GitHub.



Return to Contents.