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.
At the end of this Tutorial you will be able to:
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
Adding the menu style-swapping effect
Darkening the upper part of the hero image overlay
Your first step is the create a hero block for the ‘Smoothies’ project. Follow these steps.
<!-- Begin hero block --> <header class="container-hero"> <h1>Smooth Smoothies</h1> <h2>Where flavour meets goodness</h2> </header> <!-- End hero 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% } }
In your web browser, the ‘Smoothies’ web page should look as shown below.
Now you will download the image file for this project’s website logo.
Your img sub-folder for this project will now look as shown below.
You will begin by working with two HTML files:
If you have any other files open in Visual Studio Code, you may wish to close them.
This will help you to focus only on the two HTML files you will be working with.
Your next step is to copy content from the menus template file into your index.html web page.
You can close the menus-template.html file. You are now finished working with this template.
Your next set of tasks involves making a copy of the template stylesheet file, renaming it, and then linking the renamed copy to your index.html project web page. You will also make some changes to the copied and renamed stylesheet.
First, you will make a copy of the template stylesheet for menus.
You can close the menus-template.css stylesheet. You are now finished with this template CSS file.
Now you will delete the web browser resets from your copied and renamed stylesheet.
In your project style.css stylesheet, at about line 51, you can see that the font-family for the entire web page is set to ‘Neucha’.
The decorative font is difficult to read at the small font sizes used for menu options. So let’s replace it for both desktop and mobile menus with the basic sans-serif font family instead.
All text in both the desktop and mobile menus will now display in the sans-serif font.
Next, you will link the stylesheet you have just copied, renamed and updated to your project web page.
For both the desktop and mobile menus, you need to update the website logo and its surrounding hyperlink.
<a href="#"><img src="assets/img/smoothies-logo.png" alt="website logo"></a>
In your web browser, the ‘Smoothies’ web page should look as shown below.
For both the desktop and mobile menus, you need to update the hyperlinks for the various menu options.
<ul> <li><a href="#watermelon">Watermelon</a></li> <li><a href="#apple">Apple</a></li> <li><a href="#blueberry">Blueberry</a></li> <li><a href="#lemon">Lemon</a></li> <li><a href="#email-signup-form" class="btn-cta"><i class="fas fa-envelope"></i> Newsletter</a></li> </ul>
Now that you have created hyperlinks in the desktop and mobile menus, you need to create the destinations in the web page that these links will bring the user to.
View the result in your web browser for both desktop and mobile screen sizes. Verify that the menu options all work correctly when clicked/tapped.
Because both the desktop/laptop and mobile parent containers are ‘sticky’, the menus remain fixed at the top of the screen as the user scrolls down through the web page.
This also means that the top 72px of whatever web page element immediately follows the parent menu containers is ‘hidden’ behind them.
When you click or tap a menu option, you can see that the top of the destination heading is partly ‘hidden’ behind the menubar.
To fix this issue, follow these steps:
You can see that the menu containers no longer hide any of the web page content.
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.
<img src="assets/img/profile-pic.jpg" alt="Mary Smith, Web Designer">
<a href="../../index.html">Home</a>
<a href="../index.html">Portfolio</a>
<a href="../../contact/index.html">Contact</a>
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.
In your web browser, the web page should look as shown below.
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.
In your web browser, the web page should look as shown below as you scroll down and back up the screen.
When the user scrolls down the web page:
When the user scrolls back up the web page:
In your style.css file, you can see that the hero image has a black-coloured overlay.
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.
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.
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.
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.
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.